dockerignore in Docker

From the Docker cheat sheet ยท Dockerfile ยท verified Jul 2026

.dockerignore

Exclude files from the build context to speed up builds and avoid leaking secrets

bash
# .dockerignore
node_modules
.git
.env
*.md
dist
.DS_Store
๐Ÿ’ก Without .dockerignore, Docker sends EVERYTHING in the directory to the build daemon
โšก Always ignore node_modules โ€” they get reinstalled with npm ci inside the image
๐Ÿ“Œ Ignore .env files to prevent secrets from being baked into the image
๐ŸŸข Same syntax as .gitignore โ€” supports wildcards, negation (!important.md), and comments
dockerignorebuildsecurity

Continue with Docker

Save the full cheat sheet or work through every related task.

More Docker tasks

Back to the full Docker cheat sheet