I am new to docker and I developed a simple asp.net core webapi solution which uses a NuGet package from a private repository.
dotnet restore command returns an error for a missing NuGet package that is located inside a private repository which introduced in the nuget.config file inside the solution.
does anyone knows what's the problem with my configs and dockerfile ?
Dockerfile
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetcoretssl.dll"]
.dockerignore
bin\
obj\
Also I have a nuget.config file in the solution's root directory as below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="myrepo" value="\\path\to\the\nuget_packages_folder" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
But I receive below messages from
docker build -t aspnetcoretssl .
error NU1101: Unable to find package TestContracts. No packages exist with this id in source(s): nuget.org Generating MSBuild file /app/obj/aspnetcoretssl.csproj.nuget.g.props.
The command '/bin/sh -c dotnet restore' returned a non-zero code: 1
It looks like there are two problems
The NuGet.config file is in your solution directory, but the Dockerfile is in the project folder. This means
COPY . ./won't copy NuGet.config into the Docker containerEven if you had the NuGet.config file, the "myrepo" source is an invalid filepath inside a Docker container.
This is invalid because this is a Windows network file path, but your container is running on Linux.
To solve this, I would recommend the following.
Add a second file named NuGet.linux.config, and point to this file when building on non-windows. Use the RestoreConfigFile property to point to this file when building on Linux. If you have moved NuGet.config into the project directory, adding these lines to your
aspnetcoretssl.csprojfiles would work:Creating a network mount from
\\path\to\the\nuget_packages_foldertoZ:\NuGet.linux.config, change "myrepo" to<add key="myrepo" value="/nuget/myrepo" />--volumeparameter on docker-run.docker run --volume Z:/:/nuget/myrepo