5

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

2
  • most likely you run dotnet restore inside linux container and it cannot access your custom nuget dirrectory located on some windows shared folder Commented Jan 14, 2018 at 15:05
  • @PavelAgarkov , yes this was my initial guess, but by providing nuget.config inside solution it suppose to be solved.
    – DjBuddy
    Commented Jan 14, 2018 at 18:46

1 Answer 1

1

It looks like there are two problems

  1. 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 container

  2. Even 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.

  1. Either move your Dockerfile to the solution directory, or move NuGet.config into the project directory.
  2. 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.csproj files would work:

    <PropertyGroup>
      <RestoreConfigFile Condition="'$(OS)' != 'Windows_NT'">NuGet.linux.config</RestoreConfigFile>
      <RestoreConfigFile Condition="'$(OS)' == 'Windows_NT'">NuGet.config</RestoreConfigFile>
    </PropertyGroup>
    
  3. Creating a network mount from \\path\to\the\nuget_packages_folder to Z:\

  4. In NuGet.linux.config, change "myrepo" to <add key="myrepo" value="/nuget/myrepo" />
  5. Mounting this drive into the container. This is done with the --volume parameter on docker-run. docker run --volume Z:/:/nuget/myrepo

Not the answer you're looking for? Browse other questions tagged or ask your own question.