Dockerfile can't see local file or private nuget server

后端 未结 5 1542
轮回少年
轮回少年 2021-01-11 10:38

I am trying to start my .net core web api on container tech. using docker.

Environments=Windows 10,Visual Studio

Docker version:

Clien

5条回答
  •  心在旅途
    2021-01-11 11:08

    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

提交回复
热议问题