I have a .dockerignore file in my project which uses .NET with Angular. I want to exclude the node-modules and .angular directories and have added the following lines to my .dockerignore file:
**/.angular
**/.node-modules
However, both directories are copied to the image. I check this by running
rsync -avn . /dev/shm --exclude-from .dockerignore
to see which files are send to the shm directory, based on the answer here. My IDE also displays a context consisting of 1500 files.
Now when I remove the wildcards and my .dockerignore looks like this it works flawlessly and I get a context of ~105 files:
ClientApp/.angular
ClientApp/node-modules
The Dockerfile and .dockerignore file are both in the root of the context-path (on the same level as the ClientApp directory.
From my understanding, according to the docs the special wildcard should ignore any .angular directory, no matter how many levels between the root directory and the specified directory. This assumption is based on the paragrah in the docs:
Beyond Go’s filepath.Match rules, 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.
Especially the last line has me stumped, since that's exactly my usecase. The original (first) .dockerignore file is created by Rider/VS which is why I assume that it should normally work:
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/.run
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/dist
LICENSE
README.md
I feel like I am missing something in order to fully understand how dockerignore works. I know that it hast to be at the root of the context directory which is not necessarily the root of the project.
Why are the wildcards not working? Why are they sometimes working (e.g.it is ignoring all files in the output directory bin or dist as well)? Is it only ignoring files and not directories at the root level?