Override .dockerignore file when using ADD

I have one Rockerfile that creates 4 images; I also have one central .dockerignore file. For one of the images, I need assets that are blocked by the .dockerignore file - is there a way when you do ADD or COPY to force add / ignore this list?

This will be much easier to do in one file, unlike three separate ...!

+5
source share
2 answers

There is no easy way.

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

docker daemon does not see your build folder when the build starts, all the files in the context creation folder are compressed (or simply packed) and sent to the daemon, and only after that it will read your Dockerfile before creating the container with the files it received.

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

+1
source

In a typical Docker build, the .dockerignore file affects the "build context", which is packaged and sent to the .dockerignore server at the start of the build. If the "build context" does not contain files, you cannot reference them, so files are excluded. They do not "exist" for assembly.

Rocker claims it works differently without sending the build context to the server. The code looks like this: every step of ADD / COPY consists of a tar file that ignores the files . In addition, .dockerignore is read once at startup and caching .

Since Rocker does not send an assembly context before each assembly, but only filtering for each ADD / COPY , there is hope. But due to ignoring data that is read only once at startup, you cannot do something scared, for example, copy different .dockerignore files at different stages of assembly.

Use MOUNT

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

 FROM debian:jessie ADD . /app # assets/ in .dockerignore WORKDIR /app MOUNT .:/context RUN cp -r /context/assets /app # include assets/ 

Change application structure

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

+1
source

Source: https://habr.com/ru/post/1263613/


All Articles