Home > Blockchain >  Working with dockerfile genereted by VS2019
Working with dockerfile genereted by VS2019

Time:09-29

Hi I am quite new to docker and I have a question,

I have generated for my existing project dockerfile using VS2019, and project has some refrence to other projects. But I came up with a problem, when I lunch it from VS2019 it works, it creates docker images and adds all referenced projects and I can use it.

So next thing I gave created docker-compose.yml like:

version: '3.9'

services:
  app:
    build: .
    ports:
        - 80:80
        - 443:443

And I have started getting errors after using docker-compose run, so I tried docker build (docker compose and dockerfile are inside App.Server folder) and this is what I am receiving:

ERROR [build  3/10] COPY [App.Server/App.Server.csproj, App.Server/]
ERROR [build  4/10] COPY [App.Components/App.Components.csproj, App.Components/]                                                                                                                                        
ERROR [build  5/10] COPY [../serverbackend/CL.Logic/CL.Logic.fsproj, ../serverbackend/CL.Logic/] 
                                                                   
 > [build  3/10] COPY [App.Server/App.Server.csproj, App.Server/]:
------
------
 > [build  4/10] COPY [App.Components/App.Components.csproj, App.Components/]:
------
------
 > [build  5/10] COPY [../serverbackend/CL.Logic/CL.Logic.fsproj, ../serverbackend/CL.Logic/]:
------
failed to compute cache key: "/serverbackend/CL.Logic/CL.Logic.fsproj" not found: not found

My dockerfile content:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["App.Server/App.Server.csproj", "App.Server/"]
COPY ["App.Components/App.Components.csproj", "App.Components/"]
COPY ["../serverbackend/CL.Logic/CL.Logic.fsproj", "../serverbackend/CL.Logic/"]
RUN dotnet restore "App.Server/App.Server.csproj"
COPY . .
WORKDIR "/src/App.Server"
RUN dotnet build "App.Server.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "App.Server.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "App.Server.dll"]

I can just assume those COPY path are wrong, but how to correct them?

CodePudding user response:

When you build a Docker image, you work in what is called the build context. You can only access files in the build context and not files outside.

The build context is normally the current directory on the host and all sub-directories. Your problem occurs when you try to go outside the build context by copying ../serverbackend/CL.Logic/CL.Logic.fsproj. Going up a directory from the root directory of the build context takes you outside the build context and isn't allowed.

A way to fix it is to move your Dockerfile up one directory and adjust all your paths in the file. Then your build context will include the serverbackend directory. By doing that, the COPY statement in question would become COPY ["serverbackend/CL.Logic/CL.Logic.fsproj", "../serverbackend/CL.Logic/"].

  • Related