1

I am trying to build an ASP.NET Core project using Dockerfile. I need to use multiple package-sources to restore the project. so I defined the package-sources into a NuGet.config file.

Using docker, I want to copy the NuGet.config file to my working directory so that the dotnet restore command can use it to restore from.

Here is how my Dockerfile look like

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
LABEL stage=build-env
WORKDIR /app

# Copy and build
COPY ./src /app
COPY ./NuGet.config /app
RUN dotnet restore /app/Project.Web --configfile ./app/NuGet.config
RUN dotnet publish /app/Project.Web -c Release -o ./build/release --framework net6.0 --no-restore

Unfortunately, the above script errors on this line COPY ./NuGet.config /app

=> ERROR [build-env 4/6] COPY ./NuGet.config /app failed to compute cache key: "/NuGet.config" not found: not found

How can I correctly copy the NuGet.config file over to my working directory?

Jay
  • 1,168
  • 13
  • 41
  • Does this answer your question? [How to use Docker's COPY/ADD instructions to copy a single file to an image](https://stackoverflow.com/questions/31640660/how-to-use-dockers-copy-add-instructions-to-copy-a-single-file-to-an-image) – Kenny Apr 27 '22 at 16:50
  • TL;DR; add a `/` after the app => `COPY ./NuGet.config /app/` – Kenny Apr 27 '22 at 16:51
  • @Kenny thank you for the comment. this did not fix the problem. I get `failed to compute cache key: "/NuGet.config" not found: not found` the NuGet.config file is located at the same directory as the Dockerfile – Jay Apr 27 '22 at 16:54
  • 4
    After a quick search, it might be because of the .dockerignore or the .gitignore. If the config is listed inside one of them it won't copy – Kenny Apr 27 '22 at 16:59
  • That indeed was the issue! I had to add `!NuGet.config` into `.dockerignore` file and the copy worked – Jay Apr 27 '22 at 17:15

0 Answers0