I have a repository with several projects inside. Sometimes there's some code sharing and I have to set up the context to be a common root. Troubles arise when there are several images that use the same context, but require different sets of files.
This takes away the simplicity of maintaining a small context and using a straightforward COPY
to preserve structure. What would really help is if I could specify something akin to:
x-foo: &foo
build:
context: .
dockerfile: ./foo/Dockerfile
dockerignore: ./foo/.dockerignore
x-bar: &bar
build:
context: .
dockerfile: ./bar/Dockerfile
dockerignore: ./bar/.dockerignore
My first intuition is that this is straying too far from the intended purpose of .dockerignore
to really be desirable. Additionally, this is not supported by the Docker Engine and could lead to unexpected issues even if handled properly client-side.
Finally, I'm wary of condoning usage that involves arcane file whitelisting/blacklisting interactions. This is the wrong solution to your issue, IMO.
Related topics/discussions in moby/moby;
I second this. Maintaining microservice monorepo may be very tiring sometimes - especially when you have to maintain dozens of almost identical .dockerignore files.
I don't quite follow... Is it not standard practice to have a docker-compose.yml with services that each have their own context & Dockerfile? And then have a unique .dockerignore file in each directory that has a Dockerfile?
@dm17 AFAIK it doesn't work if you need the context to be the root folder (or simply the same folder for 2 different services with different ignores).
It seems DOCKER_BUILDKIT supports the Dockerfile.dockerignore convention, but it is not available on windows hosts so not helpful in my case.
Most helpful comment
I don't quite follow... Is it not standard practice to have a docker-compose.yml with services that each have their own context & Dockerfile? And then have a unique .dockerignore file in each directory that has a Dockerfile?