Dockerfile can't see local file or private nuget server

后端 未结 5 1584
轮回少年
轮回少年 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 10:53

    Stumbled across this while looking for another nuget question/answer...

    To restore from within docker, as mentioned in this answer copy a nuget.config file to the container first, I'd suggest you place this in /root/.nuget/NuGet folder and use a multistage Dockerfile, that way, you don't need to worry about removing it.

    If it helps, this is my setup...

    --nuget.config
    
    
      
        
      
      
        
          
          
        
      
    
    

    Multi-stage Dockerfile...

    FROM mcr.microsoft.com/dotnet/core/sdk:3.1.201 as sdk-build
    WORKDIR /app
    
    # Skip extraction of XML documentation for nuget packages
    ENV NUGET_XMLDOC_MODE=skip
    
    # We'll copy the nuget config file to the right place
    # which should mean it doesn't get copied to our deployed containers
    # and we can just call 'dotnet restore' with specifying a config file
    COPY ./Nuget.Config /root/.nuget/NuGet/NuGet.Config
    
    # Make use of cached layers, by only doing a restore when the config changes
    COPY ./*.sln ./**/*.csproj ./
    
    # Then within a RUN command to copy them to the right folders.
    RUN for file in $(ls *.csproj); do mkdir -p ${file%.*}/ && mv $file ${file%.*}/; done \
        && dotnet restore
    
    # Copy the source code
    COPY . .
    
    # Now do a build/publish here
    RUN dotnet publish "./project/project.csproj" --output /app/output
    
    
    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.2
    WORKDIR /app
    COPY --from=sdk-build /app/output ./
    ENTRYPOINT ["./project"]
    

提交回复
热议问题