Why is Docker-compose failing to copy local files to the container

I am building a simple DotnetCore application with docker-compose support with VS2017.

I have two Dockerfile, one for the app and one for an NGINX proxy. On top of that, there is a docker-compose.yml file that wraps both of these together.

This is the aspnetcore app Dockerfile, there's many COPY statement in there and they all work properly!

FROM microsoft/dotnet:2.0-runtime AS base
WORKDIR /app

FROM microsoft/dotnet:2.0-sdk AS build
WORKDIR /src
COPY CoreServer.sln ./
COPY CoreServer/CoreServer.csproj CoreServer/
RUN dotnet restore -nowarn:msb3202,nu1503
COPY . .
WORKDIR /src/CoreServer
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Release -o /app

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

This is the nginx Dockerfile which can't manage to copy files properly. Instead, it outputs the following error:

COPY failed: stat /var/lib/docker/tmp/docker-builder780242597/nginx.conf: no such file or directory. #1859

FROM nginx

WORKDIR /etc/nginx

COPY nginx.conf ./
COPY server.crt ./
COPY server.key ./

I tried building this Dockerfile by itself and it works, but when I use docker-compose it gives the error above.

This is what the docker-compose.yml file looks like

version: '3'

services:
  coreserver:
    image: coreserver
    build:
      context: .
      dockerfile: CoreServer/Dockerfile
    expose:
      - "5000"

  nginx:
    build: 
      context: .
      dockerfile: nginx/Dockerfile
    ports:
      - "80:80"
      - "443:443"
    links:
      - coreserver

If you want to look at the full project, it's a dotnetcore websocket server test application with a server and a client application.

https://github.com/avboivin/WssCoreServer/tree/master/server

Can somebody tell me what I'm doing wrong to have docker send give this particular error ?


From https://docs.docker.com/engine/reference/builder/#copy. says :

COPY obeys the following rules:

  • The [src] path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

  • If [src] is a directory, the entire contents of the directory are copied, including filesystem metadata.

so it's not bugs . COPY cannot read files from your absolute path.

so the solution is to create your docker-compose.yml in same directory with your SOURCE dir/files and run it.


It would seem this is a bug.

I found the solution here :

https://github.com/docker/for-mac/issues/1922#issuecomment-355364451

Which was simply moving the Dockerfile that was having issues at the root level of the docker-compose.yaml file.