I am trying to start my .net core web api on container tech. using docker.
Environments=Windows 10,Visual Studio
Docker version:
Clien
Copying the Nuget.Config
to the solution or project folder will work if your 'private nuget feed' is accessible via a url.
But if the private feed is a local folder used as a nuget source, this approach will still fail with an error that the folder is outside the build context or simply because the Windows path does not get resolved by the Docker build process.
e.g. if you Nuget.Config
has something like this:
the Docker context will not resolve C:\dev\nuget-packages
It's tempting to just give up on building within docker and just pre-publish the compiled solution and build the image from that...
But another workaround, requiring a few more steps, is also possible:
run dotnet restore
before running the docker-compose
command, and use the --packages
option to save the restored packages to the solution folder
e.g.
dotnet-restore C:\slnfolder\myproj\myapp.csproj --packages C:\slnfolder\packages
(This could be wrapped in a single powershell script along with the docker-compose
command.)
Then in the Dockerfile (used by docker-compose
to build the image), assuming context is the solution folder and WORKDIR
is '/src'
COPY packages/. packages/.
and modify the Dockerfile restore line to
RUN dotnet restore "myproj/myapp.csproj" -s /src/packages -s https://api.nuget.org/v3/index.json