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
Related
I am trying to create simple Hello World AWS Lambda function in .Net core 3.1 using Visual studio and trying to build docker image locally using command prompt.
When I execute docker build -t Dockerfile . command, its giving following error:
------
> [build 4/7] RUN dotnet restore "base/AWSDockerLambda.csproj":
#12 1.555 Determining projects to restore...
#12 3.592 /usr/share/dotnet/sdk/3.1.421/NuGet.targets(128,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/src/base/AWSDockerLambda.csproj]
#12 3.592 /usr/share/dotnet/sdk/3.1.421/NuGet.targets(128,5): error : The SSL connection could not be established, see inner exception. [/src/base/AWSDockerLambda.csproj]
#12 3.592 /usr/share/dotnet/sdk/3.1.421/NuGet.targets(128,5): error : The remote certificate is invalid according to the validation procedure. [/src/base/AWSDockerLambda.csproj]
------
Can anyone please help me here? Below is my Dockerfile:
FROM amazon/aws-lambda-dotnet:core3.1 AS base
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["AWSDockerLambda.csproj", "base/"]
RUN dotnet restore "base/AWSDockerLambda.csproj"
WORKDIR "/src"
COPY . .
RUN dotnet build "AWSDockerLambda.csproj" --configuration Release --output /app/build
FROM build AS publish
RUN dotnet publish "AWSLambdas3.csproj" \
--configuration Release \
--framework netcoreapp3.1 \
--self-contained false \
--output /app/publish
FROM base AS final
WORKDIR /var/task
COPY --from=publish /app/publish .
CMD ["AWSDockerLambda::AWSDockerLambda.Function::FunctionHandler"]
Objective -> I am currently trying to integrate Dapr with a small sample project provided by the .Net project templates. At the end of my test cases, I would like to use Docker Compose to launch multiple containers for a web API and a web app to communicate with each other using the Dapr sidecars.
Problem -> Whenever I run docker compose up on the sample application, the container fails to be created and is stopped by this error:
> [build 4/7] RUN dotnet restore "MyBackEnd/MyBackEnd.csproj":
#0 0.945 Determining projects to restore...
#0 7.179 /src/MyBackEnd/MyBackEnd.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#0 7.202 Failed to restore /src/MyBackEnd/MyBackEnd.csproj (in 6.09 sec).
Steps to Reproduce ->
The following are the steps I took with this project:
Ran mkdir sample_project && cd sample_project
Ran dotnet new webapi -o MyBackEnd followed by cd MyBackEnd
Ran touch Dockerfile && cd .. && touch docker-compose.yml
I then put this in my Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
WORKDIR /app
RUN apt-get update && apt-get install -y libcurl4
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /src
COPY ["MyBackEnd/MyBackEnd.csproj", "MyBackEnd/"]
RUN dotnet restore "MyBackEnd/MyBackEnd.csproj"
COPY . .
WORKDIR "/src/MyBackEnd"
RUN dotnet build "MyBackEnd.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyBackEnd.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyBackEnd.dll"]
And this was what I did with my Docker Compose YAML file:
version: '3.4'
services:
mybackend:
image: ${DOCKER_REGISTRY-}mybackend
build:
context: .
dockerfile: MyBackEnd/Dockerfile
ports:
- "3000:80"
Finally, I ran docker compose up to arrive at the issue
Additional Information -> I am not running this on a Windows system. I am using Ubuntu 20, and thus, I do not have access to Visual Studio to handle the launching and configuration for me. I am aware that this is a heavily replicated question, but I have yet to see anything that specifically applies to users that do not have access to Visual Studio or on Ubuntu. Thanks!
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 trying to run my first .Net Core Web API(Core 2.2) on Docker in local host. I enabled Docker support(Linux) while creating the project.
Docker File
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["SampleApp/SampleApp.csproj", "SampleApp/"]
RUN dotnet restore "SampleApp/SampleApp.csproj"
COPY . .
WORKDIR "/src/SampleApp"
RUN dotnet build "SampleApp.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "SampleApp.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SampleApp.dll"]
When I try to run the API on Docker from VS, I get the following error
Error CTP1001 An error occurred while attempting to build Docker image.
and when I looked into the output window
1>------ Build started: Project: SampleApp, Configuration: Debug Any CPU ------
1>SampleApp -> E:\Sandbox\ContainerDeployment\SampleApp\SampleApp\bin\Debug\netcoreapp2.2\SampleApp.dll
1>docker build -f "E:\Sandbox\ContainerDeployment\SampleApp\SampleApp\Dockerfile" -t sampleapp:dev --target base --label "com.microsoft.created-by=visual-studio" "E:\Sandbox\ContainerDeployment\SampleApp"
1>#1 [internal] load build definition from Dockerfile
1>#1 transferring dockerfile: 32B done
1>#2 [internal] load .dockerignore
1>#2 sha256:0237a52bf01ebc117c468d73e0fc890d42166c17898aa5c4fd0fd96dcaee67e8
1>#1 sha256:bb73acd705ce58a2a5ccfdd8d06dc6e46e04a03a430562efdf99961870d2e178
1>#2 transferring context: 34B done
1>
1>#2 DONE 0.0s
1>
1>#3 sha256:2209054a124f7bc1424fa6735d588f36916bcec272f45a5e3e54f7288e65d73e
1>#3 [internal] load metadata for docker.io/microsoft/dotnet:2.2-aspnetcore-runtime
1>#1 DONE 0.0s
1>#3 ERROR: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
1>------
1>------
1> > [internal] load metadata for docker.io/microsoft/dotnet:2.2-aspnetcore-runtime:
1>failed to solve with frontend dockerfile.v0: failed to create LLB definition: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
1>C:\Users\gopalk\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.4.10\build\Container.targets(258,5): error CTP1001: An error occurred while attempting to build Docker image.
1>Done building project "SampleApp.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
.NET Core version 2.2 is not supported anymore, the current LTS .NET version is 6.0. You can see the existing image versions of ASP.NET Core runtime on docker hub.
Updating .NET version on your machine:
If you are using Visual Studio you can use the Visual Studio Installer to install .NET 6 and all the templates that come with it. Then you should either recreate your project with .NET version 6, or upgrade you existing projects to .NET 6 and then re-generate your dockerfile, You can generate a Dockerfile in Visual Studio by right clicking the project file --> add --> docker support, before these steps you should delete your existing dockerfile.