Dockerfile can't see local file or private nuget server Dockerfile can't see local file or private nuget server docker docker

Dockerfile can't see local file or private nuget server


In order for a dotnet command running inside a container to find your custom feeds, the nuget.config file must also be copied to the container.

To do this, add a nuget.config file with your private feed to your project folder and add an additional COPY step that copies this file to the container.

Example (Dockerfile):

WORKDIR ...COPY NuGet.Config /COPY ... ...


for those who have landed here as they were using private repositories or custom nuget feeds and RUN dotnet restore is failing ,then here is what you can do :

Applicable especially if : your NuGet.Config contains the private repo endpoint and credentials , then

1) copy your system's NuGet.Config in project folder at same root level where .csproject is.

2) now in docker file put these statements just before you try to restore package:

COPY ./NuGet.Config ./

3) after that , append the config file location in dotnet restore command like this :

RUN dotnet restore <CS_project_name>.csproj --configfile ./NuGet.Config

4) Now do rest of the thing which you wanted to do .

5) just at the end before entry point or before copying to other container(in case of multistage build) , it is good idea to remove NuGet.Config,as we don’t want that to be available in pod/container to be seen

RUN rm ./NuGet.Config


You can add the private nuget through dotnet command, without the need to link to nuget.config file.

COPY *.csproj ./  RUN dotnet nuget add source <source-value-of-nuget> -n <name> RUN dotnet restore