Is there a way to use a .dockerignore
file conditionally?
I have a huge C# codebase, and I obviously have a lot of tests.
But tests contain lots of miscelanious data (~100-150mb
for all the tests in the whole codebase).
I would like to build an image only for testing and on an other image, just take what matters (- tests
, - other miscleanious stuff
)
Or should this be the case where I need to create a build script just for my use case?
2
Answers
Docker ignore files have the same syntax as git ignore files.
This means you can use globs and negations to ignore, but otherwise include different sections on the file tree
You should not be bundling your application test resources into your final application image, however, so sounds like you need a multi-stage docker image or other test and build scripts that contain your conditions
If you enable BuildKit as your builder backend, then you can define a dockerignore specific to a certain Dockerfile:
So by enabling BuildKit (by setting the variable
DOCKER_BUILDKIT=1
), you can have atesting.Dockerfile
with its owntesting.Dockerfile.dockerignore
.