Reputation: 666
I am very much new on docker technology, I am getting the build error while creating the .Net Core 3.1 on Azure DevOps CI pipeline on Docker image tasks:
Step 7/17 : COPY ["API2/API2.csproj", "API2/"] COPY failed: CreateFile \?\C:\ProgramData\docker\tmp\docker-builder021493529\API2\API2.csproj: The system cannot find the path specified.
My default docker file is
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["API1/API1.csproj", "API1/"]
RUN dotnet restore "API1/API1.csproj"
COPY . .
WORKDIR "/src/API1"
RUN dotnet build "API1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "API1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "API1.dll"]
Please do let me know from where I am doing mistake.
Here are the docker tasks:
Here are the folder and files structure on azure DevOps as well:
Upvotes: 0
Views: 405
Reputation: 19026
COPY ["API1/API1.csproj", "API1/"]
Based on the error message, this should the line that caused the error message.
Step1:
Please ensure you did not configure the .dockerignore
file to exclude this file: API1/API1.csproj
, which must exists in the directory where you run your build from.
Step2:
After above confirmed, now we can consider the error is caused about the server could not find the csproj
file correctly by following the context and the path you provided.
According to the your original definition: API1/API1.csproj
, I guess the actual path of API1.csproj
in your repository should be src/API1/API1.csproj
, right?
If yes, here has 2 method you can try:
1). Change the COPY
definition as:
COPY ["API1.csproj", "API1/"]
Updated:
When you apply this method, you may succeed to COPY, but failed with Program does not contain a static 'Main' method suitable for an entry point *****
.
Here it means that the COPY . .
does not copy the files correctly.
At this time, please also change the COPY . .
to COPY . API1/
. This will add folder to dest path.
2). Another way is you could specify API1
to Build context
in task:
Below is what I am using, and I do not need make any changes into my dockerfile
:
you can input $(Build.Repository.LocalPath)
by replacing hard code the context:
Updated:
In Docker 2.*, you can also leave Build context to **
:
You can refer to my previous answer on such question: #1.
Based on my opinions, I am not recommend the first method I mentioned above, because it let your dockerfile
different with the one which you can run successfully in Visual studio.
Upvotes: 1