In the same directory I have two Dockerfiles and I would like to add a separate .dockerignore for each of them.
Currently, I have:
Dockerfile.npm
Dockerfile.nginx
But can I have something like this?:
.dockerignore.npm
.dockerignore.nginx
In the same directory I have two Dockerfiles and I would like to add a separate .dockerignore for each of them.
Currently, I have:
Dockerfile.npm
Dockerfile.nginx
But can I have something like this?:
.dockerignore.npm
.dockerignore.nginx
You can now use multiple .dockerignore files in Docker.
Firstly you need to enable BuildKit mode; this is done either by setting:
export DOCKER_BUILDKIT=1
or by adding this configuration:
{ "features": { "buildkit": true } }
to the Docker daemon configuration in ~/.docker/daemon.json and restarting the daemon. This will be enabled by default in future.
You also need to prefix the name of your .dockerignore file with the Dockerfile name.
So if your Dockerfile is called OneApp.Dockerfile the ignore file needs to be called OneApp.dockerignore.
All taken from this comment: https://github.com/moby/moby/issues/12886#issuecomment-480575928
Multiple dockerignore files or specifying which dockerignore file to use is currently not supported by Docker.
See this issue on Github: Add support for specifying .dockerignore file with -i/--ignore