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