.dockerignore pattern to exclude files in all subdirectories

Patterns like *.pyc are matched only at the beginning of the path, or for the files directly below the context directory, but not recursively. To make it work recursively the **/ syntax must be used:

# Ignore generated files
**/*.pyc

The reference at How to create a dockerignore file doesn’t put that clear enough.

Finally, I understood that trick. For some reason, I wasn’t able to find any mention of this and haven’t found any example Dockerfile with such construct, so documenting it here. Was it trivial for everybody else?

Leave a Comment