Docker-compose and .dockerignore

You have 2 Dockerfiles, which have their separate contexts. In each context (folder) you have .dockerignore, and that is correct. But .dockerignore does not work outside of build context, that means using ../../ is wrong.

I guess you are supposing these files to apply to docker folder, but in fact they apply to docker/app and docker/web respectively.

The build process is following:

First docker cli packs the context (folder with Dockerfile if not specified explicitly) and sends it to docker daemon. Nothing outside this folder is sent. It is written explicitly for COPY command, which is used to put the context items into container:

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 there is .dockerignore, the ignored files are excluded before packing.


The .dockerignore needs to be in the root directory/context folder as you specified in the docker-compose.yml


What worked for me is to put the .dockerignore at the root of my app, where the docker-compose.yml is.