How to use it
- Leave Docker and Git files and Secrets ticked: they are useful in almost every project.
- Tick your language and, if needed, editors and OS files.
- Add your own patterns, for example a folder of test fixtures.
- Save the result as
.dockerignorein the build context root, usually next to theDockerfile.
How it works
The chosen lists are combined in a fixed order: Docker and Git, secrets, languages, editors, OS files, then your own patterns. A pattern that already appeared in an earlier group is not repeated, and a group left empty by that is dropped.
Docker matches each line against paths relative to the context root. * matches within one folder, ** matches any number of folders, and ! re-includes files excluded before.
Example
The default choice (Docker and Git, secrets, Node.js, OS files) starts like this:
# Docker and Git
.git
.gitignore
.dockerignore
Dockerfile*
docker-compose*.yml
compose*.yaml
**/*.log
# Secrets
.env
.env.*
!.env.example
**/*.pem
**/*.key
and goes on with **/node_modules, npm and pnpm logs, coverage, dist, **/.DS_Store and **/Thumbs.db.
Tips
- Excluding
node_modulesmatters for more than speed: dependencies installed on your machine may be built for another system. Install them inside the image instead. - If your Dockerfile copies a prebuilt file, such as
target/app.jarordist/, untick that group or add an exception with!. - Run
docker build --no-cache .after big changes to check that the image still builds without the ignored files.