Override .dockerignore file when using ADD Override .dockerignore file when using ADD docker docker

Override .dockerignore file when using ADD


In a simple way no.

The .dockerignore file is used to filter what will be used in the build before even reading the Dockerfile.

The docker daemon does not see your build folder, when the build starts, all the files in the context build folder are compressed (or just packed) and send to the daemon and only then it will read your Dockerfile to build the container with the files it received.

More content about .dockerignore: https://docs.docker.com/engine/reference/builder/#/dockerignore-file


In a normal Docker build the .dockerignore file affects the "build context" that is packaged up and sent to the docker server at the beginning of the build. If the "build context" doesn't contain the files then you can't reference them, so this is how the files are excluded. They don't "exist" for the build.

Rocker claims to run differently by not sending a build context to the server. The code looks like each ADD/COPY step is composed into a tar file that ignores the files. Also, the .dockerignore is read once at startup and cached.

As Rocker is not sending the build context before each build, only filtering for each ADD/COPY command, there is hope. But due to the ignore data being read only once at startup you can't do anything funky like copying different .dockerignore files at different stages of the build though.

Use MOUNT

One option is to continue using the .dockerignore as is and use a Rocker MOUNT command to manually copy the ignored directories. Their last example in the mount section demonstrates:

FROM debian:jessieADD . /app                       # assets/ in .dockerignoreWORKDIR /appMOUNT .:/contextRUN cp -r /context/assets /app   # include assets/

Change App Structure

The only other useful option I can think of is to split out your ADD or COPY into multiple commands so that you don't rely on the the .dockerignore to filter files to the other 3 images. This would probably require your assets directory to be stored outside of your application root.