Dockerignore

2 snippets in Docker

DKDocker

.dockerignore — Exclude Build Context

DK · Dockerfile
syntax
# .dockerignore file
pattern
dir/
example
node_modules
.git
*.md
.env
dist
.DS_Store
coverage

Note Place this file next to your Dockerfile. Without it, Docker sends everything in the build context to the daemon, including node_modules (hundreds of MB), .git history, and possibly secrets in .env files. This is one of the highest-impact optimizations you can make.

Always Use .dockerignore

DK · Best Practices
syntax
# .dockerignore
example
node_modules
.git
*.md
.env*
coverage
dist
.DS_Store
__pycache__
*.pyc
.venv

Note Without .dockerignore, a COPY . . sends everything to the daemon including .git (often 100MB+), node_modules, environment files with secrets, and test coverage reports. Builds become slow and images become bloated.