I have self-hosted linux build agent in Azure DevOps. I try to build&push docker task and i have an error like this(locally dotnet build worked):
The specified task executable "node" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/src/Cillian.csproj]
My log:
...
Step 11/26 : RUN dotnet build -c Release -o /app
---> Running in 9233fd642015
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 1.51 sec for /src/Cillian.csproj.
/root/.nuget/packages/microsoft.typescript.msbuild/3.0.0/tools/Microsoft.TypeScript.targets(293,5): error MSB6003: The specified task executable "node" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/src/Cillian.csproj]
...
Pipeline: AzureDevOpsImg
My Dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY *.csproj ./
RUN dotnet restore
COPY . .
WORKDIR /src
RUN dotnet build -c Release -o /app
FROM build AS publish
RUN dotnet publish -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Cillian.dll"]
No such file or directory
Just focus on this error message, dotnet build could not find the csproj file to continue the build. This is the mostly prone error in Azure devops even if it can be built successfully in local.
That is because the docker runs at the Repos/solution level locally(e.g. VS). BUT, for Azure devops CI, it running the docker in the directory where the dockerfile lives, which is at project level.
The nutshell is the relative path which can succeed to used in the local to find csproj, not avilable in the Azure devops at all. Because the working directory has changed.
Please specify $(Build.Repository.LocalPath) to the Docker 2.* argument Build context.
For YAML:
- task: Docker#2
displayName: build
inputs:
containerRegistry: DockerHub
repository: xxx/xxx
Dockerfile: Docker/TestWebApi/Dockerfile
buildContext: '$(Build.Repository.LocalPath)' # Specify the context
tags: latest
Related
I created a web-project named ProjectService and added docker-support for it using Visual Studio 2022. I can build and debug the image pretty well from within VS.
Now I try to build and run the image from the command-line in order to have it within my build-pipeline. So I execute this from the root-directory of my repo:
docker build -t myrep/demo:latest ./ProjectService
However when I do that I get the following error:
#11 ERROR: "/ProjectService/ProjectService.csproj" not found: not found
#12 [build 4/8] COPY [DatabaseManager/DatabaseManager.csproj, DatabaseManager/]
#12 sha256:b881c00e01ebb7ea687c2f8c5d5f585e237bf6151b63cd21110ed1a7bdf74af6
#12 ERROR: "/DatabaseManager/DatabaseManager.csproj" not found: not found
I think this is because within my docker-file paths are relative:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ProjectService/ProjectService.csproj", "ProjectService/"]
COPY ["DatabaseManager/DatabaseManager.csproj", "DatabaseManager/"]
RUN dotnet restore "ProjectService/ProjectService.csproj"
COPY . .
WORKDIR "/src/ProjectService"
RUN dotnet build "ProjectService.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ProjectService.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProjectService.dll"]
when I execute docker from within the ProjectService-drectory itself, I get the same error, though.
My folder-structure is this:
root
ProjectService
ProjectService.csproj
DockerFile
DatabaseManager
DatabaseManager.csproj
where ProjectService depends on DatabaseManager.
Your Dockerfile looks like it assumes that the build context is the root directory.
So to build it you can either do it from the root directory with
docker build -t myrep/demo:latest -f ProjectService/Dockerfile .
or from the ProjectService directory with
docker build -t myrep/demo:latest ..
A 3rd option is to move the Dockerfile to the root directory. Then your Dockerfile will be in the directory that's assumed to be the build context. That's how most projects are organized. Then you can build with
docker build -t myrep/demo:latest .
After creating and developing WEB Api in c#, I wanted to add docker file and run API in docker container.
My docker file is named Dockerfile, with content like this:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["WebAPI/WebAPI.csproj", "WebAPI/"]
RUN dotnet restore "WebAPI/WebAPI.csproj"
COPY . .
WORKDIR "/src/WebAPI"
RUN dotnet build "WebAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebAPI.dll"]
After building docker file, the Visual Studio code is promted this message in console:
Severity Code Description Project File Line Suppression State
Error CTC1014 Docker command failed with exit code 1.
The command 'cmd /S /C dotnet build "WebAPI.csproj" -c Release -o /app/build' returned a non-zero code: 1 WebAPI c:\devops projekti\web api gir\webapi\dockerfile 1
I do a multistage build right now. The first stage compiles with credentials for my internal repos and I just keep the binaries as per this example: https://github.com/dotnet/dotnet-docker/blob/master/documentation/scenarios/nuget-credentials.md
But I want to run in CI server and need to provider the CI server with test and coverage reports. It would be most elegant to do this in the build layer but how do I get files out of a docker image during build?
For example:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj .
COPY ./nuget.config .
RUN dotnet restore
# Copy and publish app and libraries
COPY . .
############ Get this files out #####################
# Generate test report. copy this to external directory
RUN dotnet test --logger trx
# Generate coverage report. copy this to external directory
RUN dotCover.sh dotnet --output=myRep.html --reportType=HTML -- test
#######################################################
RUN dotnet publish -c Release -o out --no-restore
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 AS runtime
WORKDIR /app/
COPY --from=build /app/out ./
ENTRYPOINT ["dotnet", "dotnetapp.dll"]
So I want to be able to run docker build and have it dump a test and coverage report to the current directory where docker build command was run. Is this possible? It would make this seamless for CI because all server must do is run docker build and it get reports
docker build supports an --output flag. I think it requires BuildKit (DOCKER_BUILDKIT=1). Here's one example usage.
https://docs.docker.com/engine/reference/commandline/build/ - then find --output on the page
https://docs.docker.com/engine/reference/commandline/build/#output
I am attempting to build a .Net Core 3.0 (preview) project in a DevOps build pipeline.
The steps in my azure-pipelines.yml executes up to the "docker build" step, successfully initiating the build process.
The Docker file is read and executed up to the "dotnet build" step after which the following error is thrown.
error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/" to the destination file "/app/", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles. [/src/.csproj]
I have attempted to build locally by executing dotnet build ".csproj" -c Release -o /app
The build then succeeds with 0 errors and 0 warnings. Could this be related to an SDK issue in DevOps?
Any advice would be greatly appreciated.
The build command from my Docker file.
RUN dotnet build "<project>.csproj" -c Release -o /app
--- {OMITED}
---1ff83de4bdba
Step 5/16 : WORKDIR /src
---Running in 972629766fad
Removing intermediate container 972629766fad
---1325ecd8e7c3
Step 6/16 : COPY ["<projectname>.csproj", "<projectname>/"]
---a4ba463683dc
Step 7/16 : RUN dotnet restore "<projectname>/<projectname>.csproj"
---Running in 82bb9095d412
Restore completed in 14.08 sec for /src/<projectname>/<projectname>.csproj.
Removing intermediate container 82bb9095d412
---7b0cc236782e
Step 8/16 : COPY . .
---884bb695bfb3
Step 9/16 : WORKDIR /src
---Running in 817b001e2060
Removing intermediate container 817b001e2060
---40b8690ecb63
Step 10/16 : RUN dotnet build "<projectname>.csproj" -c Release -o /app
---Running in 48d79b81c3cb
Microsoft (R) Build Engine version 16.0.462+g62fb89029d for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 531.02 ms for /src/<projectname>.csproj.
/usr/share/dotnet/sdk/3.0.100-preview5-011568/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(157,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [/src/<projectname>.csproj]
/usr/share/dotnet/sdk/3.0.100-preview5-011568/Microsoft.Common.CurrentVersion.targets(4560,5): error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/<projectname>" to the destination file "/app/<projectname>", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles. [/src/<projectname>.csproj]
Build FAILED.
/usr/share/dotnet/sdk/3.0.100-preview5-011568/Microsoft.Common.CurrentVersion.targets(4560,5): **error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/<projectname>" to the destination file "/app/<projectname>", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles. **[/src/<projectname>.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:11.43
The command '/bin/sh -c dotnet build "<projectname>.csproj" -c Release -o /app' returned a non-zero code: 1
##[error]Bash exited with code '1'.
##[section]Finishing: docker build
In my case the Assembly name of my project was the same as the name of the project and also the same as the directory name of that project. Once I changed the assembly name in the project properties to something else, this error was gone.
in my case i had to rename the project folder to be different than the project itself in dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY ["<project-name>.csproj", "<project-name>_build/"]
RUN dotnet restore "<project-name>_build/<project-name>.csproj"
I am assuming this is an issue with the .Net Core 3.0 preview5 SDK. I have created the project in .Net Core 2.2 and it build successfully.
When adding the following parameters on the dotnet build command, the build succeeds in .Net Core 3.0
RUN dotnet build ".csproj" -c Release -r linux-musl-x64 -o /app --no-restore
The DockerFile below built successfully in DevOps
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY ["<project-name>.csproj", "<project-name>/"]
RUN dotnet restore "<project-name>/<project-name>.csproj" -r linux-musl-x64
COPY . "<project-name>/"
WORKDIR "/src/<project-name>"
RUN dotnet build "<project-name>.csproj" -c Release -r linux-musl-x64 -o /app --no-restore
FROM build AS publish
RUN dotnet publish "<project-name>.csproj" -c Release -r linux-musl-x64 -o /app --no-restore
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "<project-name>.dll"]
I've created an asp.net core signalr project. It builds great. Image builds fine. I publish to my private repository. However, when I try to pull the image down onto a Windows 2016 server I get an error message: docker : a Windows version 10.0.17134-based image is incompatible with a 10.0.14393 host
I don't see where I'm targeting a specific platform, and the research that I've done seems like this should run
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /app
COPY ./*.csproj ./EntityStatusChangeService/
RUN dotnet restore ./EntityStatusChangeService/EntityStatusChangeService.csproj
COPY ./. ./EntityStatusChangeService/
WORKDIR /app/EntityStatusChangeService
RUN dotnet publish -c Release -o out
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS runtime
WORKDIR /app
COPY --from=build /app/EntityStatusChangeService/out ./
ENTRYPOINT ["dotnet", "EntityStatusChangeService.dll"]