I'm having trouble building a Docker Image of my project. In my project I have a project reference from an application, which is not in the same solution as my project. When I try to build my Docker image I get the following errors/warnings:
PS C:\Trunk\Tools\Dashboard> docker build -f Server/Dockerfile --force-rm -t dashboardserver .
[+] Building 228.2s (15/17)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 579B 0.1s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0 0.9s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0 0.0s
=> [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:6.0 0.0s
=> [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:6.0#sha256:a2a8f968b043349b8faa0625c5405ac33da70b3274ff9e17109430f16aa9a3ee 0.0s
=> [internal] load build context 2.2s
=> => transferring context: 1.32MB 2.2s
=> CACHED [base 2/2] WORKDIR /app 0.0s
=> CACHED [final 1/2] WORKDIR /app 0.0s
=> CACHED [build 2/7] WORKDIR /src 0.0s
=> CACHED [build 3/7] COPY [Server/Server.csproj, Server/] 0.0s
=> [build 4/7] RUN dotnet restore "Server/Server.csproj" 94.6s
=> [build 5/7] COPY . . 0.2s
=> [build 6/7] WORKDIR /src/Server 0.2s
=> ERROR [build 7/7] RUN dotnet build "Server.csproj" -c Release -o /app/build 102.3s
------
> [build 7/7] RUN dotnet build "Server.csproj" -c Release -o /app/build:
#15 3.459 Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
#15 3.459 Copyright (C) Microsoft Corporation. All rights reserved.
#15 3.459
#15 4.336 Determining projects to restore...
#15 4.341 Skipping project "/SomeApp/Api/SomeApp.Api.csproj" because it was not found.
#15 4.343 Skipping project "/SomeApp/Api/SomeApp.Api.csproj" because it was not found.
#15 4.729 All projects are up-to-date for restore.
#15 5.139 /usr/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(2065,5): warning : The referenced project '../../../SomeApp/Api/SomeApp.Api.csproj' does not exist. [/src/Server/Server.csproj]
#15 97.00 /src/Server/Program.cs(9,7): error CS0246: The type or namespace name 'SomeApp' could not be found (are you missing a using directive or an assembly reference?) [/src/Server/Server.csproj]
#15 98.57
#15 98.57 Build FAILED.
#15 98.57
#15 98.57 /usr/share/dotnet/sdk/6.0.201/Microsoft.Common.CurrentVersion.targets(2065,5): warning : The referenced project '../../../SomeApp/Api/SomeApp.Api.csproj' does not exist. [/src/Server/Server.csproj]
#15 98.57 /src/Server/Program.cs(9,7): error CS0246: The type or namespace name 'SomeApp' could not be found (are you missing a using directive or an assembly reference?) [/src/Server/Server.csproj]
#15 98.57 1 Warning(s)
#15 98.57 1 Error(s)
#15 98.57
#15 98.57 Time Elapsed 00:01:35.02
------
executor failed running [/bin/sh -c dotnet build "Server.csproj" -c Release -o /app/build]: exit code: 1
The Dockerfile which is used:
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 ["Server/Server.csproj", "Server/"]
RUN dotnet restore "Server/Server.csproj"
COPY . .
WORKDIR "/src/Server"
RUN dotnet build "Server.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Server.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Server.dll"]
EXPOSE 5004
The directory looks as follows:
\Trunk\Tools\Dashboard (my application with its own solution)
\Trunk\SomeApp (other application with its own solution)
+- SomeApp.sln
+- Api ("project" folder)
+- SomeApp.Api.csproj
Project reference in dashboard.sln:
<ItemGroup>
<ProjectReference Include="..\..\..\SomeApp\Api\SomeApp.Api.csproj" />
</ItemGroup>
I tried to build a Docker image of my application, and I expected to get a Docker image, so I could build a Docker container. I totally get that it can't find the 'SomeApp' application, because I'm not pushing it to the Docker image. But how could I solve this problem?
(Edit: removed unreadable JPG and added cmd lines. Also added Dockerfile, which is used at the moment. For the minimal reproducible example there are two project solutions needed, with the same file structure as shown above. )
Related
need a little help resolving this issue I'm facing when building my ASP.NET project that references a local class library inside a docker container.
I'm using:
ASP.NET 6.0
Docker version 20.10.21, build baeda1f
dotnet sdk 6.0
When I try to run
docker build .
I get the following error:
=> ERROR [build 7/7] RUN dotnet build "ProjectName.csproj" -c Debug -o /app/build 1.9s
------
> [build 7/7] RUN dotnet build "ProjectName.csproj" -c Debug -o /app/build:
#15 0.434 MSBuild version 17.3.2+561848881 for .NET
#15 0.655 Determining projects to restore...
#15 0.885 All projects are up-to-date for restore.
#15 1.042 /usr/share/dotnet/sdk/6.0.404/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "PackageName". Check to make sure the assembly exists on disk. If this reference is required
by your code, you may get compilation errors. [/src/ProjectName/ProjectName.csproj]
#15 1.847 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProjectName/ProjectName.csproj]
#15 1.852
#15 1.852 Build FAILED.
#15 1.852
#15 1.852 /usr/share/dotnet/sdk/6.0.404/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "PackageName". Check to make sure the assembly exists on disk. If this reference is required
by your code, you may get compilation errors. [/src/ProjectName/ProjectName.csproj]
#15 1.852 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProjectName/ProjectName.csproj]
#15 1.852 1 Warning(s)
#15 1.852 1 Error(s)
#15 1.852
#15 1.852 Time Elapsed 00:00:01.38
------
executor failed running [/bin/sh -c dotnet build "ProjectName.csproj" -c Debug -o /app/build]: exit code: 1
The dockerfile I'm using
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 ["ProjectName.csproj", "ProjectName/"]
RUN dotnet restore "ProjectName/ProjectName.csproj"
COPY .. .
WORKDIR "/src/ProjectName"
RUN dotnet build "ProjectName.csproj" -c Publish -o /app/build
FROM build AS debug
RUN dotnet publish "ProjectName.csproj" -c Publish -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProjectName.dll"]
The .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
....
</ItemGroup>
<ItemGroup>
<Reference Include="PackageName">
<HintPath>..\..\PackageName\PackageName\bin\Debug\netstandard2.1\PackageName.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Any thoughts on me getting the dockerfile to fetch the package .dll on build? or is it the wrong way to go about getting what I want?
I am open to hosting the package on nuget but for the time being this dockerfile is for dev purposes only.
Keep in mind that the package is at the right location locally, as building the project using:
dotnet build ProjectName.csproj
works fine
P.S. I replaced the package name with "PackageName" and the project name with "ProjectName".
I tried building the dockerfile for ASP.NET 6.0 and I expected it to pass, but I got an Error instead.
So I solved this almost immediately, I made the class library build to the location with my asp.net project, cleared the docker cache, and built again.
Id project located on your computer, You need to copy xxx.dll after define
SWORKDIR /src
COPY ["Xxx.csproj", "."]
COPY ["output/Debug/net6.0/xxx.dll", "."]
Otherwise you have to create nuget package the dll then you install from nuget
I'm trying to containerize an ASP.NET Core & Angular app but I'm having some trouble.
I'm getting these errors:
=> [internal] load build definition from Dockerfile 0.4s
=> => transferring dockerfile: 872B 0.1s
=> [internal] load .dockerignore 0.4s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0 0.5s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:5.0 0.0s
=> [base 1/7] FROM mcr.microsoft.com/dotnet/aspnet:5.0 0.0s
=> [build 1/7] FROM mcr.microsoft.com/dotnet/sdk:5.0#sha256:b69acf0a0734d77827d4e7ce22421256a64d490bb3ce988b21c4 0.0s
=> [internal] load build context 0.3s
=> => transferring context: 3.17kB 0.0s
=> CACHED [base 2/7] WORKDIR /app 0.0s
=> CACHED [base 3/7] RUN apt-get -y update 0.0s
=> CANCELED [base 4/7] RUN apt-get -y upgrade 5.6s
=> CACHED [build 2/7] WORKDIR /src 0.0s
=> CACHED [build 3/7] COPY [mediere.csproj, .] 0.0s
=> CACHED [build 4/7] RUN dotnet restore "./mediere.csproj" 0.0s
=> CACHED [build 5/7] COPY . . 0.0s
=> CACHED [build 6/7] WORKDIR /src/. 0.0s
=> CACHED [build 7/7] RUN dotnet build "mediere.csproj" -c Release -o /app/build 0.0s
=> ERROR [publish 1/1] RUN dotnet publish "mediere.csproj" -c Release -o /app/publish 4.7s
------
> [publish 1/1] RUN dotnet publish "mediere.csproj" -c Release -o /app/publish:
#21 1.567 Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET
#21 1.567 Copyright (C) Microsoft Corporation. All rights reserved.
#21 1.567
#21 2.460 Determining projects to restore...
#21 2.852 All projects are up-to-date for restore.
#21 3.883 mediere -> /src/bin/Release/net5.0/mediere.dll
#21 3.894 mediere -> /src/bin/Release/net5.0/mediere.Views.dll
#21 4.006 /bin/sh: 2: /tmp/tmp045a9cb1e4954d54b304a781ae210094.exec.cmd: npm: not found
#21 4.011 /src/mediere.csproj(38,5): error MSB3073: The command "npm install" exited with code 127.
------
executor failed running [/bin/sh -c dotnet publish "mediere.csproj" -c Release -o /app/publish]: exit code: 1
My dockerfile is this:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 5000
#EXPOSE 5001
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt install -y curl
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y nodejs build-essential
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["mediere.csproj", "."]
RUN dotnet restore "./mediere.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "mediere.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "mediere.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "mediere.dll"]
I expected it to work, because I'm installing npm on line 12.
What I have observed is that the publish task and the apt-get install tasks work in the same time, and I think that publish goes before apt-get install and that's why it doesn't work. I might be wrong though.
How can I fix this error?
Thanks.
Each of the Dockerfile build stages starts FROM some other image. At the point you're using Node, that build stage is
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
...
FROM build AS publish
RUN dotnet publish "mediere.csproj" -c Release -o /app/publish
In this particular sequence of packages, starting from the .NET SDK image up through the point you run dotnet publish, but this never actually installs Node.
Where you do install Node it's in a base image stage. That's included into the final image, but not in any of the intermediate build steps.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
RUN apt-get install -y nodejs
FROM base AS final
If you're building the Angular application into static files and then serving it from the .NET application, you only need Node during the build-and-publish phase, but not in the final application. I'd suggest installing it immediately after the FROM ... AS build line, and in particular before you COPY anything into the image. This will avoid reinstalling Node if you rebuild the image due to a code change.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
# do not install Node here
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
# Do install Node
# The default version in the Debian repositories should be fine
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
build-essential \
nodejs
# Build your application as before
WORKDIR /src
...
FROM build AS publish
# Will include Node, because the `FROM ... AS build` stage installed it
FROM base AS final
# Will not include Node, because the `FROM ... AS base` stage did not
# install it
I'm trying executing a "docker build" in my application .Net 6.0, but I receive an error in Dotnet restore in Dockerfile.
The application executing normally local, not any error.
Docker command:
docker build -t aspnetcore-docker-image .
Error in terminal:
=> ERROR [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj 0.2s
------
> [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj:
#11 0.185 Could not execute because the application was not found or a compatible .NET SDK is not installed.
#11 0.185 Possible reasons for this include:
#11 0.185 * You intended to execute a .NET program:
#11 0.185 The application 'restore' does not exist.
#11 0.185 * You intended to execute a .NET SDK command:
#11 0.185 It was not possible to find any installed .NET SDKs.
#11 0.185 Install a .NET SDK from:
#11 0.185 https://aka.ms/dotnet-download
------
executor failed running [/bin/sh -c dotnet restore ./DevFreela.API/DevFreela.API.csproj]: exit code: 145
My Dockerfile
# .NET Core SDK
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS build
# Sets the working directory
WORKDIR /app
# Copy Projects
#COPY *.sln .
COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/
COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/
COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/
COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/
# .NET Core Restore
RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj
# Copy All Files
COPY Src ./
# .NET Core Build and Publish
RUN dotnet publish ./DevFreela.Api/DevFreela.Api.csproj -c Release -o /publish
# ASP.NET Core Runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY --from=build /publish ./
EXPOSE 80 5195 7066
ENV ASPNETCORE_URLS=http://+:5195;https://+:7066
ENTRYPOINT ["dotnet", "DevFreela.API.dll"]
Project structure:
Complete terminal log:
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 938B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0 0.6s
=> [internal] load build context 0.0s
=> => transferring context: 13.14kB 0.0s
=> [runtime 1/3] FROM mcr.microsoft.com/dotnet/aspnet:6.0#sha256:26ef9dc4aa354cc4aa4ae533c97f92d0d72c5e848f6968660be51d9 0.0s
=> CACHED [runtime 2/3] WORKDIR /app 0.0s
=> CACHED [build 3/9] COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/ 0.0s
=> CACHED [build 4/9] COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/ 0.0s
=> CACHED [build 5/9] COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/ 0.0s
=> CACHED [build 6/9] COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/ 0.0s
=> ERROR [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj 0.2s
------
> [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj:
#11 0.185 Could not execute because the application was not found or a compatible .NET SDK is not installed.
#11 0.185 Possible reasons for this include:
#11 0.185 * You intended to execute a .NET program:
#11 0.185 The application 'restore' does not exist.
#11 0.185 * You intended to execute a .NET SDK command:
#11 0.185 It was not possible to find any installed .NET SDKs.
#11 0.185 Install a .NET SDK from:
#11 0.185 https://aka.ms/dotnet-download
------
executor failed running [/bin/sh -c dotnet restore ./DevFreela.API/DevFreela.API.csproj]: exit code: 145
You're using the aspnet image which doesn't contain the SDK, so you can't build using that. You need the sdk image for the first part of your Dockerfile like this
# .NET Core SDK
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
# Sets the working directory
WORKDIR /app
# Copy Projects
#COPY *.sln .
COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/
COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/
COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/
COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/
# .NET Core Restore
RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj
# Copy All Files
COPY Src ./
# .NET Core Build and Publish
RUN dotnet publish ./DevFreela.Api/DevFreela.Api.csproj -c Release -o /publish
# ASP.NET Core Runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY --from=build /publish ./
EXPOSE 80 5195 7066
ENV ASPNETCORE_URLS=http://+:5195;https://+:7066
ENTRYPOINT ["dotnet", "DevFreela.API.dll"]
I am hosting my own build-agent on my on-premises windows server.
However, when I either try to build my docker image using the default agent or my on-premisses agent, it cannot copy the .cproj files.
What I want, is to be able to build this image without the errors.
What I have tried so far is:
Changes work directory to: ../ , ../../ and ~/
Google for solutions, but this does not result in anything, because it is too specific or something.
Please note that it also does not work on an agent from DevOps itself (windows-2022)
Does anyone know what I could have done wrong or overlooked?
Directories:
src/Server/DockerFile
src/Server/Server.csproj
And so on for the other .csproj files
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
ENV ASPNETCORE_URLS=https://+:5005;http://+:5006
WORKDIR /app
EXPOSE 5005
EXPOSE 5006
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /
COPY ["src/Server/Server.csproj", "src/Server/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Shared/Shared.csproj", "src/Shared/"]
COPY ["src/Infrastructure.Shared/Infrastructure.Shared.csproj", "src/Infrastructure.Shared/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
COPY ["src/Client/Client.csproj", "src/Client/"]
COPY ["src/Client.Infrastructure/Client.Infrastructure.csproj", "src/Client.Infrastructure/"]
RUN dotnet restore "src/Server/Server.csproj" --disable-parallel
COPY . .
WORKDIR "src/Server"
RUN dotnet build "Server.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Server.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
WORKDIR /app/Files
WORKDIR /app
ENTRYPOINT ["dotnet", "DeDenDannenburcht.Server.dll"]
My Pipeline
Pipeline Output
"C:\Program Files\Docker\Docker\resources\bin\docker.exe" build -f F:\agents\_work\1\s\src\Server\Dockerfile -t dedendannenburcht:166 --label com.azure.dev.image.system.teamfoundationcollectionuri=https://dev.azure.com/JeremiedevosBusiness/ --label com.azure.dev.image.build.sourceversion=ab657210c8696881754f36393adee9da7394ea19 --label image.base.ref.name=mcr.microsoft.com/dotnet/aspnet:6.0 --label image.base.digest=sha256:545da8027d0de13ac88716fc380201f05ad9b4834b5b2fd95eadf277e51318a7 F:\agents\_work\1\s\src\Server
#1 [internal] load build definition from Dockerfile
#1 sha256:5cec5c1a6e883854d5ef516a04f7fbc4f77cc63f74549820c4d061dbb560e514
#1 transferring dockerfile: 1.31kB done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 sha256:8f7ecf610ac80d8ac3c3e64e4de2e264ecf11892bf7afc5ff6debe41dd69161b
#2 transferring context: 2B done
#2 DONE 0.0s
#4 [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0
#4 sha256:ac4494cbca04ddb415c76edcbcc7688784c2a6ea65dd656286c013738aa3b75f
#4 DONE 0.0s
#3 [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0
#3 sha256:9eb4f6c3944cfcbfe18b9f1a753c769fc35341309a8d4a21f8937f47e94c712b
#3 DONE 0.1s
#5 [base 1/2] FROM mcr.microsoft.com/dotnet/aspnet:6.0
#5 sha256:50f1ddc10932c4a74c7af5704e931a9489c710faea4f2381fe2380827a900e00
#5 DONE 0.0s
#6 [base 2/2] WORKDIR /app
#6 sha256:bc3cf6c390e5fe0e66017b4845c8fcf3e56c7adac9f514a00c2c986024f377a4
#6 CACHED
#7 [final 1/4] WORKDIR /app
#7 sha256:3baba3edbb555769ad9a49e827de88d7dcc4f72ad6e2b42e576964e4a30eac96
#7 CACHED
#8 [build 1/14] FROM mcr.microsoft.com/dotnet/sdk:6.0#sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec
#8 sha256:ff704f84298cdcbd6cd764720a2e1a4dcd4b44ff415133896e77ad0c5d908001
#8 resolve mcr.microsoft.com/dotnet/sdk:6.0#sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec done
#8 sha256:0af6b8199917326984baa1452533da610b46f65bfbc5296c7f81cb72d3beec84 2.01kB / 2.01kB done
#8 sha256:dc243ad423c72b21b838c1362ca152823b0b379a546887d8c47c437357576fb2 7.31kB / 7.31kB done
#8 sha256:664e00cfda3df2ac7370c116f04a17d636fc041b62bdd9a0b88a60b987344269 0B / 136.50MB 0.1s
#8 sha256:a3dd4dee05cd1369014244d03b28b602e6a2e1650210dd8633322e00379471ec 2.17kB / 2.17kB done
#8 sha256:4253139ebd4dcee5f7878254306eb794d0f2a80ee4ca8d085d0b9e507412fb1e 0B / 25.36MB 0.1s
#10 sha256:aa96c6c99b71465c230e63fb1edea0588e2b25c39d6b44fc1381e7cbe48c15d9
#10 ERROR: "/src/Server/Server.csproj" not found: not found
#13 [build 5/14] COPY [src/Shared/Shared.csproj, src/Shared/]
#13 sha256:8fd70ae770f73428f5ff667da9b5080dff2b8035dbeb1247fe9e76d5890ad27d
#13 ERROR: "/src/Shared/Shared.csproj" not found: not found
#16 [build 8/14] COPY [src/Client/Client.csproj, src/Client/]
#16 sha256:33c15418c5097a788d8ef568338206ce45e5fea62b707a2be13c136b28ca43e9
#16 ERROR: "/src/Client/Client.csproj" not found: not found
#15 [build 7/14] COPY [src/Infrastructure/Infrastructure.csproj, src/Infrastructure/]
#15 sha256:4f643811b59a89db4a864a2a40a7ff2cc05709c3b123027874b72ff436af0d56
#15 ERROR: "/src/Infrastructure/Infrastructure.csproj" not found: not found
#17 [build 9/14] COPY [src/Client.Infrastructure/Client.Infrastructure.csproj, src/Client.Infrastructure/]
#17 sha256:b7385969b745977db24f702bc1c8f0b931cd675b9f44e70870ae2d918632e9b3
#17 ERROR: "/src/Client.Infrastructure/Client.Infrastructure.csproj" not found: not found
#14 [build 6/14] COPY [src/Infrastructure.Shared/Infrastructure.Shared.csproj, src/Infrastructure.Shared/]
#14 sha256:f101a94226cbf6f38fe9d908da512ded2bd68070207a6dd5c003d8967252c970
#14 ERROR: "/src/Infrastructure.Shared/Infrastructure.Shared.csproj" not found: not found
#12 [build 4/14] COPY [src/Domain/Domain.csproj, src/Domain/]
#12 sha256:152a7025db6bab6e2e456a9ab7ef8436cc9689411341ea38c362df78a0d058c1
#12 ERROR: "/src/Domain/Domain.csproj" not found: not found
#11 [build 3/14] COPY [src/Application/Application.csproj, src/Application/]
#11 sha256:1760818b73b46bb8ebf75492933a413de08fd2ab7a26cae37de4ae4a5f60b83e
#11 ERROR: "/src/Application/Application.csproj" not found: not found
------
> [build 2/14] COPY [src/Server/Server.csproj, src/Server/]:
------
------
> [build 3/14] COPY [src/Application/Application.csproj, src/Application/]:
------
------
> [build 4/14] COPY [src/Domain/Domain.csproj, src/Domain/]:
------
------
> [build 5/14] COPY [src/Shared/Shared.csproj, src/Shared/]:
------
------
> [build 6/14] COPY [src/Infrastructure.Shared/Infrastructure.Shared.csproj, src/Infrastructure.Shared/]:
------
------
> [build 7/14] COPY [src/Infrastructure/Infrastructure.csproj, src/Infrastructure/]:
------
------
> [build 8/14] COPY [src/Client/Client.csproj, src/Client/]:
------
------
> [build 9/14] COPY [src/Client.Infrastructure/Client.Infrastructure.csproj, src/Client.Infrastructure/]:
------
failed to compute cache key: "/src/Client.Infrastructure/Client.Infrastructure.csproj" not found: not found
##[error]The process 'C:\Program Files\Docker\Docker\resources\bin\docker.exe' failed with exit code 1
Finishing: Build an image
The Dockerfile is located under src\Server. The Build an image step calls docker build -f .\src\Server\Dockerfile .\src\Server which will not work because that is already one level too deep in the directory tree.
So there are several options:
Call docker build -f .\src\Server\Dockerfile . from the root directory, but use a custom shell script rather than the official Build an image step - it seems to have that kind of limitation.
Use relative paths in the Dockerfile like this:
COPY ["../src/Server/Server.csproj", "src/Server/"]
Move the Dockerfile to the root directory.
I've generated a basic Kubernetes Web Application in Visual Studio 2019, v16.11.1, which allowed me to automatically generate a Dockerfile and start debugging. However, upon switching to a Release configuration, the build fails when the internal dotnet restore command executes. Apparently upon trying to pull Nuget packages from a feed, the dotnet restore rejects the SSL certificate provided by the Nuget feed server.
My question is, what am I doing wrong? I started with literally the default web application program generated by Visual Studio, and it automatically fails when I try to build a Release config. See here for more detail:
The Issue
The following Dockerfile can be built in a debug configuration, but not in a Release configuration.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["KubernetesWebApp/KubernetesWebApp.csproj", "KubernetesWebApp/"]
RUN dotnet restore "KubernetesWebApp/KubernetesWebApp.csproj"
COPY . .
WORKDIR "/src/KubernetesWebApp"
RUN dotnet build "KubernetesWebApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "KubernetesWebApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "KubernetesWebApp.dll"]
Clicking "Debug" to start a debug session executes the following build, and I can debug the application:
docker build -f ".\KubernetesWebApp\Dockerfile" --force-rm -t kuberneteswebapp:dev --target base --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=KubernetesWebApp" .
However, upon attempting the following build command, the dotnet restore command fails due to a remote SSL certificate check failure:
docker build -t kuberneteswebapp:latest -f KubernetesWebApp/Dockerfile .
This elicits the following error:
[+] Building 7.7s (12/17)
=> [internal] load build definition from Dockerfile 0.4s
=> => transferring dockerfile: 32B 0.2s
=> [internal] load .dockerignore 0.3s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:3.1 0.8s
=> [internal] load metadata for mcr.microsoft.com/dotnet/core/sdk:3.1 0.8s
=> [internal] load build context 0.3s
=> => transferring context: 644B 0.1s
=> [build 1/7] FROM mcr.microsoft.com/dotnet/core/sdk:3.1#sha256:aa984bf37de864afe9f34bc80e42412dd95702b94731a481821eeae364df77ae 0.2s
=> => resolve mcr.microsoft.com/dotnet/core/sdk:3.1#sha256:aa984bf37de864afe9f34bc80e42412dd95702b94731a481821eeae364df77ae 0.2s
=> [base 1/2] FROM mcr.microsoft.com/dotnet/core/aspnet:3.1#sha256:9280563285e34929fdae56b8759d8050169b3ce125a5dced64945b3b51e79918 0.3s
=> => resolve mcr.microsoft.com/dotnet/core/aspnet:3.1#sha256:9280563285e34929fdae56b8759d8050169b3ce125a5dced64945b3b51e79918 0.3s
=> CACHED [base 2/2] WORKDIR /app 0.0s
=> CACHED [final 1/2] WORKDIR /app 0.0s
=> CACHED [build 2/7] WORKDIR /src 0.0s
=> CACHED [build 3/7] COPY [KubernetesWebApp/KubernetesWebApp.csproj, KubernetesWebApp/] 0.0s
=> ERROR [build 4/7] RUN dotnet restore "KubernetesWebApp/KubernetesWebApp.csproj" 5.5s
------
> [build 4/7] RUN dotnet restore "KubernetesWebApp/KubernetesWebApp.csproj":
#12 3.363 Determining projects to restore...
#12 5.397 /usr/share/dotnet/sdk/3.1.412/NuGet.targets(128,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/src/KubernetesWebApp/KubernetesWebApp.csproj]
#12 5.397 /usr/share/dotnet/sdk/3.1.412/NuGet.targets(128,5): error : The SSL connection could not be established, see inner exception. [/src/KubernetesWebApp/KubernetesWebApp.csproj]
#12 5.397 /usr/share/dotnet/sdk/3.1.412/NuGet.targets(128,5): error : The remote certificate is invalid according to the validation procedure. [/src/KubernetesWebApp/KubernetesWebApp.csproj]
------
executor failed running [/bin/sh -c dotnet restore "KubernetesWebApp/KubernetesWebApp.csproj"]: exit code: 1
What I Think the Problem Is
I think the issue arises when :
The docker container attempts to pull Nuget packages from a nuget feed,
During identity verification it checks the provided server certificate
Due to some specified validation procedure, the server certificate fails verification.
What I've Tried to Fix It
I've tried the following commands to force the application to download new base container images, but to no avail:
Attempt 1:
docker build --no-cache --pull -t kuberneteswebapp:latest -f KubernetesWebApp/Dockerfile .
Result: Same error as before
Attempt 2:
docker system prune
docker image prune -a
docker build --no-cache --pull -t kuberneteswebapp:latest -f KubernetesWebApp/Dockerfile .
result: Same error as before
Neither of these efforts have succeeded. Can anyone help me? I'm at a loss here.
The issue fixed itself. I just reattempted both my test and actual projects and it works now. This could have been a software update or a computer restart. But everything works now.
If you are using Windows containers, I recommend switching to a Linux container and trying it out again. (You can do so by right clicking the Docker desktop icon in the system tray bar).
I came across the following issue on GitHub: https://github.com/docker/for-win/issues/2760#issuecomment-430889666 I was unable to reproduce your issue with a fresh ASP .NET Web API