0

So i have a solution structure like this:

sln 
--.sln
--docker-compose
--nuget.config
|
---- Project1 
------ src 
-------- Project1 
---------- csproj
---------- Dockerfile

I am trying to do something like this in my dockerfile but it is saying that the nuget.config doesn't exist : failed to compute cache key: "../../../nuget.config" not found: not found

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app

ENV NUGET_USER=user
ARG NUGET_TOKEN
ENV NUGET_TOKEN=$NUGET_TOKEN

# Copy csproj and restore as distinct layers
COPY ["Project1.csproj", "./"]
COPY ../../../nuget.config ./
RUN dotnet restore "./Project1.csproj"

# Copy everything else and build
COPY . ./
RUN dotnet build "Project1.csproj" -c Release -o /app/build

FROM build-env AS publish
RUN dotnet publish "Project1.csproj" -c Release -o /app/out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
#WORKDIR /app
COPY --from=publish /app/out .

ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080

ENTRYPOINT ["dotnet", "Project1.dll"]

if I change COPY ../../nuget.config ./ to COPY ./nuget.config ./ and add a copy of my nuget.cofig to the project1 directory, it runs fine, but i don't want to have to duplicate that file across each project.

My intellisense recognized the path i am trying as valid, but i assume when i do my docker compose that it is actually living somewhere else. What's the proper syntax to account for this?

Paul DeVito
  • 1,542
  • 3
  • 15
  • 38
  • You need to run `docker build` from the top-level `sln` directory, or in a Compose context, use `.` as the `build:` or `build: { context: }` directory. `COPY` paths then need to be relative to that top-level directory. You can't `COPY` files from outside that context directory; `COPY ../...` doesn't work and the leading `..` are silently dropped. – David Maze Nov 05 '21 at 14:36
  • So i am functionally running this with a `docker compose up --build command`. wouldn't this have the build context and allow my to just do `./`? – Paul DeVito Nov 05 '21 at 14:39
  • The context path is specified in the `docker-compose.yml` file. – David Maze Nov 05 '21 at 14:39
  • oh good point. i'll play with that. thanks – Paul DeVito Nov 05 '21 at 14:40

0 Answers0