Optimize Docker builds with comprehensive .dockerignore templates for 87+ technologies
Why
.dockerignorematters: Docker sends your entire build context to the daemon. A.dockerignorefile excludes unnecessary files, making builds faster, more secure, and more efficient.
- 🚀 Quick Start
- 📊 Why Use .dockerignore?
- 📁 Template Categories
- 🛠️ How to Use Templates
- 📋 Best Practices
- 🔧 Advanced Usage
- ❓ Frequently Asked Questions
- 📚 Template Standards
- 🤝 Contributing
- 📄 License
- 🌐 Website
- 💖 Support
# React project
curl -o .dockerignore https://raw.githubusercontent.com/ronald2wing/.dockerignore/master/frameworks/react.dockerignore
# Django project
curl -o .dockerignore https://raw.githubusercontent.com/ronald2wing/.dockerignore/master/frameworks/django.dockerignore
# Node.js project
curl -o .dockerignore https://raw.githubusercontent.com/ronald2wing/.dockerignore/master/languages/node.dockerignore
# Python project with security
curl -o .dockerignore https://raw.githubusercontent.com/ronald2wing/.dockerignore/master/languages/python.dockerignoredockerignore.com - Browse templates and generate custom .dockerignore files with our interactive generator.
# 1. Copy a framework template (recommended for most projects)
cp frameworks/react.dockerignore .dockerignore
# 2. Combine language and common templates (for custom projects)
cat languages/python.dockerignore common/security.dockerignore > .dockerignore
# 3. Download directly from GitHub
wget https://raw.githubusercontent.com/ronald2wing/.dockerignore/master/frameworks/nextjs.dockerignore -O .dockerignore| Benefit | Impact | Example |
|---|---|---|
| Faster Builds | 50-90% reduction in context size | 500MB → 50MB |
| Enhanced Security | Sensitive files never reach Docker | .env, credentials, keys |
| Better Caching | Cache layers stay valid longer | node_modules/ changes don't invalidate cache |
| Smaller Images | Unnecessary files excluded | Development tools, test files |
| Improved CI/CD | Faster pipeline execution | Quicker deployments |
| Reduced Bandwidth | Less data transferred to Docker daemon | Faster remote builds |
# Without .dockerignore
$ docker build --no-cache .
Sending build context to Docker daemon 512.3MB
# With .dockerignore
$ docker build --no-cache .
Sending build context to Docker daemon 45.2MB # 91% reduction!| Project Type | Without .dockerignore | With .dockerignore | Reduction |
|---|---|---|---|
| React App | 450MB | 35MB | 92% |
| Django Project | 380MB | 42MB | 89% |
| Node.js API | 520MB | 48MB | 91% |
| Python ML Project | 1.2GB | 85MB | 93% |
Self-contained, security-first templates for specific frameworks
- Location:
frameworks/ - Design Philosophy: Complete, standalone templates with security patterns first
- Examples:
react.dockerignore,django.dockerignore,spring-boot.dockerignore,vue.dockerignore,nextjs.dockerignore - Usage: Use standalone - includes all necessary patterns including security
- Best For: Projects using specific frameworks (React, Django, Vue, etc.)
Language-specific patterns for modular combination
- Location:
languages/ - Design Philosophy: Language-specific only, designed for combination
- Examples:
node.dockerignore,python.dockerignore,java.dockerignore,go.dockerignore,rust.dockerignore - Usage: Combine with common templates for complete coverage
- Best For: Custom projects or when no framework template exists
Cross-cutting concerns for all projects
- Location:
common/ - Design Philosophy: Reusable patterns for common concerns
- Examples:
security.dockerignore,cache.dockerignore,logs.dockerignore,testing.dockerignore,docker.dockerignore - Usage: Combine with language templates for granular control
- Best For: Adding specific functionality to language templates
Build and deployment tool patterns
- Location:
tools/ - Design Philosophy: Tool-specific patterns
- Examples:
vite.dockerignore,webpack.dockerignore,vercel.dockerignore,rollup.dockerignore - Usage: Add to framework or language templates as needed
- Best For: Projects using specific build tools
Editor and IDE configuration files
- Location:
ides/ - Design Philosophy: Editor-specific configuration files
- Examples:
visual-studio-code.dockerignore,intellij.dockerignore,vim.dockerignore,sublime-text.dockerignore - Usage: Add when using specific IDEs
- Best For: Development environments with IDE configurations
Operating system-specific files
- Location:
os/ - Design Philosophy: OS-specific temporary and system files
- Examples:
linux.dockerignore,macos.dockerignore,windows.dockerignore - Usage: Add for multi-platform projects
- Best For: Projects developed across multiple operating systems
# Single framework template (self-contained)
cp frameworks/react.dockerignore .dockerignore
# Or for other frameworks
cp frameworks/django.dockerignore .dockerignore
cp frameworks/vue.dockerignore .dockerignore
cp frameworks/nextjs.dockerignore .dockerignoreWhy use framework templates?
- Self-contained with all necessary patterns
- Security patterns included first
- No need to combine with other templates
- Tested and validated for the specific framework
# Basic combination: Language + Security
cat languages/python.dockerignore \
common/security.dockerignore > .dockerignore
# Comprehensive combination
cat languages/javascript.dockerignore \
common/security.dockerignore \
common/cache.dockerignore \
common/logs.dockerignore \
common/testing.dockerignore > .dockerignore
# Remove duplicates when combining
cat languages/python.dockerignore \
common/security.dockerignore \
common/cache.dockerignore | sort -u > .dockerignore# Example 1: Python web project with tools
cat languages/python.dockerignore \
common/security.dockerignore \
common/cache.dockerignore \
common/logs.dockerignore \
tools/docker.dockerignore > .dockerignore
# Example 2: JavaScript project with IDE
cat languages/javascript.dockerignore \
common/security.dockerignore \
tools/webpack.dockerignore \
ides/visual-studio-code.dockerignore > .dockerignore
# Example 3: Multi-platform project
cat frameworks/react.dockerignore \
os/linux.dockerignore \
os/macos.dockerignore \
os/windows.dockerignore > .dockerignoreVisit dockerignore.com to:
- Select your technology stack
- Customize patterns
- Generate and download
.dockerignorefile - Copy to clipboard for immediate use
# Always include security patterns in your .dockerignore
# Framework templates include these automatically
# For language templates, add them manually:
cat common/security.dockerignore >> .dockerignoreCritical security patterns to always include:
.env*- Environment configuration files*.key,*.pem,*.crt- Certificates and keyscredentials.json,secrets.yml- Credential filesfirebase.json,service-account-key.json- Service account keys
# Test what files are being excluded
docker build --no-cache . 2>&1 | grep -i "sending\|context"
# Check context size
docker build --no-cache . 2>&1 | grep "Sending build context"
# Test specific patterns
touch .env test.log node_modules/
docker build --no-cache . 2>&1 | grep -i "excluding\|including"# Remove duplicate patterns when combining templates
cat template1 template2 | sort -u > .dockerignore
# Check for duplicates in existing file
sort .dockerignore | uniq -d
# Remove duplicates from existing file
sort -u .dockerignore > .dockerignore.tmp && mv .dockerignore.tmp .dockerignore- Quarterly Review: Review your
.dockerignorefile every 3 months - Technology Updates: Update when adding new tools or dependencies
- Pattern Optimization: Remove patterns for tools you no longer use
- Security Review: Ensure security patterns are current and comprehensive
Framework templates are optimized and include:
- ✅ Security patterns first (critical for safety)
- ✅ Language-specific patterns
- ✅ Framework-specific patterns
- ✅ Build and cache directories
- ✅ Testing and documentation files
- ✅ IDE and tool configurations (as needed)
.dockerignore supports several pattern matching rules:
# Basic patterns
node_modules/ # Directory
*.log # Wildcard for extension
**/temp # Any directory named temp
temp? # Single character wildcard
!README.md # Exclusion (include this file)
# Exclude development dependencies
node_modules/
vendor/
__pycache__/
# Exclude build artifacts
dist/
build/
*.egg-info/
# Exclude IDE files
.vscode/
.idea/
*.swp
*.swo
# Exclude OS files
.DS_Store
Thumbs.db
# Create test files
mkdir -p node_modules build dist .vscode
touch .env .env.local test.log debug.log .DS_Store
# Test with docker build
docker build --no-cache .
# Check what's being sent
docker build --no-cache . 2>&1 | tail -20# GitHub Actions example
name: Docker Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download .dockerignore
run: |
curl -o .dockerignore https://raw.githubusercontent.com/ronald2wing/.dockerignore/master/frameworks/react.dockerignore
- name: Build Docker image
run: docker build -t myapp .A: Use framework templates for framework-based projects (React, Django, Vue, etc.). Use language templates for custom projects or when no framework template exists.
A: Use cat to combine templates and sort -u to remove duplicates:
cat languages/python.dockerignore \
common/security.dockerignore \
common/cache.dockerignore | sort -u > .dockerignoreA: Add the specific pattern to your .dockerignore file:
# Add to .dockerignore
my-specific-file.txt
config/local.json
secrets/production.key
A: Use Docker build with verbose output:
docker build --no-cache . 2>&1 | grep -i "sending\|context"A: Yes! .dockerignore works with both docker build and docker-compose build.
A: .dockerignore works with both traditional Docker builder and BuildKit. BuildKit may provide additional optimizations.
A: Use **/ pattern for nested directories:
**/node_modules/ # Exclude node_modules in any directory
**/*.log # Exclude .log files in any directory
**/__pycache__/ # Exclude __pycache__ in any directory
A: Use ! to include specific files:
# Exclude all .md files
*.md
# But include README.md
!README.md
All templates follow strict standards defined in TEMPLATE_STANDARDS.md:
- Framework templates include security patterns FIRST
- Critical patterns:
.env*, credentials, keys, certificates - Regular security reviews and updates
- Standardized headers with attribution
- Clear metadata and usage notes
- Logical section organization
- Alphabetical sorting within sections
- Language-specific patterns
- Framework-specific patterns
- Build and cache directories
- Testing and documentation files
- IDE and tool configurations
- No duplicate patterns
- Tested with Docker builds
- Validated against standards
- Regular maintenance and updates
- Usage notes and combination guidance
- References to official sources
- Best practices and recommendations
- Examples and use cases
We welcome contributions! Please see CONTRIBUTING.md for guidelines on:
- Creating new templates
- Improving existing templates
- Reporting issues
- Submitting pull requests
- Testing and validation
- Fork and Clone the repository
- Follow Standards in TEMPLATE_STANDARDS.md
- Test Thoroughly with Docker builds
- Submit Pull Request with clear description
This project is licensed under the MIT License - see the LICENSE file for details.
Visit dockerignore.com for:
- Interactive template browser
- Custom
.dockerignoregenerator - Documentation and examples
- Community resources
- Latest templates and updates
If you find this project helpful, please:
- ⭐ Star the repository on GitHub
- 📢 Share with your team and community
- 🛠️ Contribute templates or improvements
- 🐛 Report issues or suggest features
- 💬 Join discussions on GitHub
- GitHub Repository: ronald2wing/.dockerignore
- Website: dockerignore.com
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Optimize your Docker builds today with comprehensive .dockerignore templates!
Key Benefits:
- ✅ Faster builds - 50-90% reduction in context size
- ✅ Enhanced security - Protect sensitive data
- ✅ Better caching - Optimize layer caching
- ✅ Smaller images - Exclude unnecessary files
- ✅ Improved CI/CD - Faster pipeline execution
Get Started Now:
# For React projects
curl -o .dockerignore https://raw.githubusercontent.com/ronald2wing/.dockerignore/master/frameworks/react.dockerignore
# Or visit
# https://dockerignore.com