Docker (.dockerignore) Template
When running `docker build`, the entire directory is sent as build context to the Docker daemon. A proper `.dockerignore` file prevents sending gigabytes of local node_modules or secret credentials into your Docker image layers.
| 1 | # Version control |
| 2 | .git |
| 3 | .gitignore |
| 4 | |
| 5 | # Dependencies (install cleanly inside Dockerfile) |
| 6 | node_modules |
| 7 | npm-debug.log |
| 8 | |
| 9 | # Secret and local environment files |
| 10 | .env |
| 11 | .env.* |
| 12 | !.env.example |
| 13 | |
| 14 | # Build and test outputs |
| 15 | dist |
| 16 | build |
| 17 | coverage |
| 18 | .next |
| 19 | .nuxt |
| 20 | |
| 21 | # Docker files |
| 22 | Dockerfile* |
| 23 | docker-compose* |
| 24 | .dockerignore |
| 25 | |
| 26 | # IDEs and OS files |
| 27 | .vscode |
| 28 | .idea |
| 29 | .DS_Store |
| 30 | *.log |
| 31 | README.md |
Key Rules & Why They Are Ignored
.gitDrastically reduces build context transfer time and prevents exposing commit history inside production images.
node_modulesForces `npm ci` to run inside the container for architecture-matching native binary builds (e.g. Linux x86/ARM).
.env*Prevents accidentally baking production passwords directly into immutable Docker image layers.
Already Committed Ignored Files? Purge from Git Cache
Adding a pattern to .gitignore does NOT delete files that were already tracked in previous commits. Run this command to remove them from tracking without deleting your local copies:
git rm -r --cached . && git add . && git commit -m "Untrack ignored files"Frequently Asked Questions About Docker (.dockerignore) .gitignore
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
Docker will transfer your entire project directory (including node_modules and .git) over the socket to the build daemon, causing sluggish builds and potentially leaking credentials into public image registries.