I'd like a common .dockerignore
file, "outside" a build context (which I assume is the directory in which the Dockerfile
is located).
So instead of this:
project/
client/
src/
.dockerignore
Dockerfile
server/
src/
.dockerignore
Dockerfile
I prefer this:
project/
client/
src/
Dockerfile
server/
src/
Dockerfile
.dockerignore
Is that allowed? Will it walk up the filesystem until root, looking for an ignore file (the way it's commonly done by other cli tools), or must it be at the same level as the Dockerfile?
There have been changes to the mechanism in recent docker versions, e.g. for custom Dockerfile.foo.dockerignore
files, which must be placed at the same level as the Dockerfile.foo
. So I'm unsure what is the current rule, and the docs don't explain.
I'm using the latest version, docker 24.0.5.
From your docs link:
From build context:
From docker build:
So you should be able to do:
Something to keep in mind using this approach: If you have only one .dockerignore file you wont be able to exclude the source code for the other builds. As a result the source code for all builds will be sent to the docker daemon in each individual build. So be careful that you are not sending large amounts of data.