Building docker image with package from private nuget feed fails - c#

I'm using the default Dockerfile generated by Visual Studio 2022 for my .NET Core 6 razor pages app. The app is using DevExpress ASP.NET Core Controls. I downloaded the necessary packages using the private Nuget feed URL supplied by the package vendor.
This is how the Dockerfile looks like:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["NuGet.Config", "."]
COPY ["DMS.Monitor/DMS.Monitor.csproj", "DMS.Monitor/"]
RUN dotnet restore "DMS.Monitor/DMS.Monitor.csproj"
COPY . .
WORKDIR "/src/DMS.Monitor"
RUN dotnet build "DMS.Monitor.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "DMS.Monitor.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DMS.Monitor.dll"]
When I try to build the image I get the following error:
#13 [build 5/8] RUN dotnet restore "DMS.Monitor/DMS.Monitor.csproj"
#13 sha256:f1029f328e1221cc75d3cbca3603f770dbb670711688ac30334449923e9ceb3f
#13 0.893 Determining projects to restore... #13 106.8 /src/DMS.Monitor/DMS.Monitor.csproj : error NU1102: Unable to find
package DevExtreme.AspNet.Core with version (>= 21.2.8) #13 106.8
/src/DMS.Monitor/DMS.Monitor.csproj : error NU1102: - Found 3
version(s) in nuget.org [ Nearest version: 20.1.3 ] #13 107.1
Failed to restore /src/DMS.Monitor/DMS.Monitor.csproj (in 1.77 min).
#13 ERROR: executor failed running [/bin/sh -c dotnet restore "DMS.Monitor/DMS.Monitor.csproj"]: exit code: 1
My project uses DevExtreme.AspNet.Core v.21.2.8 which is obviously not available in nuget.org. Is there a way I can edit the NuGet.Config file to tell Docker where it can find the correct version of the package?

You should be able to add your private feed using the command
dotnet nuget add source <package source>
Place it before the dotnet restore command in your Dockerfile.

Related

Unable to load the service index for source error for a CodeArtifact feed using a Dockerfile

It's my first question here so let me know if I have to change something or add more information.
We’re using AWS CodeArtifact for storing our packages and when we try to build a Docker image from our Dockerfile it fails because it's unable to load the source during the restore process.
We have a web API in .Net we want to deploy using AWS Fargate. This project runs smoothly from Visual Studio 2022 using Docker but we can’t build the image from PowerShell after adding our packages from CodeArtifact.
Our approach to include the credentials in the build is to pass the NuGet.Config stored on the host using Buildkit.
This’s our Dockerfile:
#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:6.0 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:49151
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY . .
WORKDIR /src
COPY ["Src/Presentation/Project.API/Project.API.csproj", "Src/Presentation/Project.API/"]
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
--mount=type=secret,id=nugetconfig \
dotnet restore "Src/Presentation/Project.API/Project.API.csproj" \
--configfile /run/secrets/nugetconfig
COPY . .
WORKDIR "/src/Src/Presentation/Project.API"
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
dotnet build "Project.API.csproj" -c Release -o /app/build \
--no-restore
FROM build AS publish
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
dotnet publish "Project.API.csproj" -c Release -o /app/publish \
--no-restore
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project.API.dll"]
Our script in PowerShell:
docker buildx build --secret id=nugetconfig,src=$HOME\AppData\Roaming\NuGet\NuGet.Config -f "Src\Presentation\Project.API\Dockerfile" -t my-dotnet-image .
Output:
#14 [build 6/9] RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages --mount=type=secret,id=nugetconfig dotnet restore "Src/Presentation/Project.API/Project.API.csproj"
--configfile /run/secrets/nugetconfig
#14 1.175 Determining projects to restore...
#14 2.504 /src/Src/Presentation/Project.API/Project.API.csproj : error NU1301: Unable to load the service index for source
https://domain-123456789012.d.codeartifact.us-east-2.amazonaws.com/nuget/repository/v3/index.json.
What are we missing here? Once we have the Dockerfile working we want to use CDK for deploying the Docker image alongside our infrastructure.
We’re using aws codeartifact login command to authenticate with the service. We work on windows with a Linux container

Getting SSL error while trying to create docker image for AWS Lambda locally

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"]

Docker dotnet restore: Unable to load the service index for source https://api.nuget.org/v3/index.json

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!

why dotnet 5 docker container fail in run time?

I have a dotnet5 Console application that is inside a solution and has dependencies on other sibling projects. I create the Docker file with visual studio tools and this is the Docker file:
FROM mcr.microsoft.com/dotnet/runtime:5.0-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["src/MyProject/MyProject.Launcher/MyProject.Launcher.csproj", "src/MyProject/MyProject.Launcher/"]
COPY ["src/MyProject/MyProject.DataAccess/MyProject.DataAcess.csproj", "src/MyProject/MyProject.DataAccess/"]
COPY ["src/MyProject/MyProject.Service/MyProject.Service.csproj", "src/MyProject/MyProject.Service/]
COPY ["src/Domain/MyProject.Domain.Model/MyProject.Domain.Model.csproj", "src/Domain/MyProject.Domain.Model/"]
RUN dotnet restore "src/MyProject/MyProject.Launcher/MyProject.Launcher.csproj"
COPY . .
WORKDIR "/src/src/MyProject/MyProject.Launcher"
RUN dotnet build "MyProject.Launcher.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyProject.Launcher.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyProject.Launcher.dll"]
building image is ok and it added normally to my local image registry but when I try to run this image and create a container I am getting this error:
It was not possible to find any compatible framework version The
framework 'Microsoft.AspNetCore.App', version '5.0.0' was not found.
No frameworks were found.
You can resolve the problem by installing the specified framework
and/or SDK.
Use this as your base image:
FROM mcr.microsoft.com/dotnet/aspnet:5.0.0-buster-slim AS base
I Think You should check docker hub and search for .NET 5 SDK then install that image on your container then its will be fixed :
I Found Dotnet 3.1 SDK but try to find dotnet 5 SDK
I think after installation this error will be fix
Sorry For my Bad English
:)

Dotnet restore Docker fail

There is problem with Docker and command dotnet restore.
I have the docker file:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["AuthAPI/AuthAPI.csproj", "AuthAPI/"]
COPY ["CommonCoreLibrary/CommonCoreLibrary.csproj", "CommonCoreLibrary/"]
RUN dotnet restore "AuthAPI/AuthAPI.csproj"
COPY . .
WORKDIR "/src/AuthAPI"
RUN dotnet build "AuthAPI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "AuthAPI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY wait /wait
RUN chmod +x /wait
COPY /cert /root/.dotnet/https
ENTRYPOINT /wait && dotnet AuthAPI.dll
and docker compose file:
authapi:
image: ${DOCKER_REGISTRY-}authapi
build:
context: .
dockerfile: AuthAPI/Dockerfile
networks:
- peopleapp
environment:
WAIT_HOSTS: db:5432
WAIT_HOSTS_TIMEOUT: 300
ports:
- "8002:443"
When I run command
docker-compose -f "docker-compose.yml" build
I have a error
Step 10/23 : RUN dotnet restore "AnalyticAPI/AnalyticAPI.csproj"
---> Running in 2d29e1367d51
Determining projects to restore...
/usr/share/dotnet/sdk/3.1.300/NuGet.targets(128,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/src/AnalyticAPI/AnalyticAPI.csproj]
/usr/share/dotnet/sdk/3.1.300/NuGet.targets(128,5): error : Connection refused [/src/AnalyticAPI/AnalyticAPI.csproj]
ERROR: Service 'analyticapi' failed to build: The command '/bin/sh -c dotnet restore "AnalyticAPI/AnalyticAPI.csproj"' returned a non-zero code: 1
Sometimes it works fine. There are warning about Connection refused, but restoring is success.
I use Windows 10 + Hyper-V + Docker Desktop + Linux Containers + NET Core 3.1.
I had a similar problem.
It's works for me:
Add curl command to dockerfile before restore:
RUN curl https://api.nuget.org/v3/index.json -k
RUN dotnet restore "AuthAPI/AuthAPI.csproj"
Build image
Remove curl command from dockerfile
Build image again

Categories

Resources