I'm having trouble with the .dockerignore
file. This is my project structure:
file.sh
file.js
file.go
file.py
subdir/
file2.go
file2.py
.dockerignore
Dockerfile
According to the .dockerignore
documentation:
(...) you may want to specify which files to include in the context, rather than which to exclude. To achieve this, specify * as the first pattern, followed by one or more ! exception patterns.
And:
Lines starting with ! (exclamation mark) can be used to make exceptions to exclusions.
Finally:
Docker also supports a special wildcard string ** that matches any number of directories (including zero). For example, **/*.go will exclude all files that end with .go that are found in all directories, including the root of the build context.
Based on that, this is my .dockerignore
file:
# ignore everything
*
# whitelist
# ---------
# python files
!**/*.py
When I build and run the container and inspect the files, I get this:
file.py
The subdir
directory is missing, subdir/file2.py
should be included. It works if I add !subdir/**/.py
to my .dockerignore
, but the idea is to include any .py
file in any subdirectory.
This is the file structure that should be present in the container:
file.py
subdir/
file2.py
What's going on here?
I found a few issues that mention this exact problem, like these:
Exception patterns in .dockerignore do not support wildcard directories dockerignore does not respect the "special wildcard **" (comment)
And it seems like it's not gonna be fixed any time soon :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With