Skip to content

ronald2wing/.dockerignore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐳 .dockerignore Templates

Optimize Docker builds with comprehensive .dockerignore templates for 87+ technologies

Website GitHub License Templates Maintenance

Why .dockerignore matters: Docker sends your entire build context to the daemon. A .dockerignore file excludes unnecessary files, making builds faster, more secure, and more efficient.

📖 Table of Contents

🚀 Quick Start

Download a Template

# 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.dockerignore

Visit Website

dockerignore.com - Browse templates and generate custom .dockerignore files with our interactive generator.

Quick Usage Examples

# 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

📊 Why Use .dockerignore?

Key Benefits

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

Real-World Impact

# 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!

Performance Benchmarks

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%

📁 Template Categories

🏗️ Framework Templates (46 templates)

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 Templates (21 templates)

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

🛡️ Common Templates (7 templates)

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

🛠️ Tool Templates (6 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

💻 IDE Templates (4 templates)

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

🖥️ OS Templates (3 templates)

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

🛠️ How to Use Templates

Method 1: Using Framework Templates (Recommended)

# 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 .dockerignore

Why 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

Method 2: Combining Language and Common Templates

# 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

Method 3: Creating Custom Combinations

# 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 > .dockerignore

Method 4: Using the Website Generator

Visit dockerignore.com to:

  1. Select your technology stack
  2. Customize patterns
  3. Generate and download .dockerignore file
  4. Copy to clipboard for immediate use

📋 Best Practices

1. Always Include Security Patterns

# Always include security patterns in your .dockerignore
# Framework templates include these automatically
# For language templates, add them manually:
cat common/security.dockerignore >> .dockerignore

Critical security patterns to always include:

  • .env* - Environment configuration files
  • *.key, *.pem, *.crt - Certificates and keys
  • credentials.json, secrets.yml - Credential files
  • firebase.json, service-account-key.json - Service account keys

2. Test Your .dockerignore File

# 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"

3. Remove Duplicate Patterns

# 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

4. Keep It Updated

  • Quarterly Review: Review your .dockerignore file 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

5. Use Framework Templates When Possible

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)

🔧 Advanced Usage

Pattern Matching Rules

.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)

Common Pattern Examples

# 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

Testing Patterns

# 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

Integration with CI/CD

# 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 .

❓ Frequently Asked Questions

Q: Should I use framework templates or language templates?

A: Use framework templates for framework-based projects (React, Django, Vue, etc.). Use language templates for custom projects or when no framework template exists.

Q: How do I combine multiple templates?

A: Use cat to combine templates and sort -u to remove duplicates:

cat languages/python.dockerignore \
    common/security.dockerignore \
    common/cache.dockerignore | sort -u > .dockerignore

Q: What if I need to exclude a specific file?

A: Add the specific pattern to your .dockerignore file:

# Add to .dockerignore
my-specific-file.txt
config/local.json
secrets/production.key

Q: How do I test if my .dockerignore is working?

A: Use Docker build with verbose output:

docker build --no-cache . 2>&1 | grep -i "sending\|context"

Q: Can I use these templates with Docker Compose?

A: Yes! .dockerignore works with both docker build and docker-compose build.

Q: What about Docker BuildKit?

A: .dockerignore works with both traditional Docker builder and BuildKit. BuildKit may provide additional optimizations.

Q: How do I handle nested directories?

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

Q: What if I need to include a file that's excluded by a pattern?

A: Use ! to include specific files:

# Exclude all .md files
*.md

# But include README.md
!README.md

📚 Template Standards

All templates follow strict standards defined in TEMPLATE_STANDARDS.md:

1. Security-First Approach

  • Framework templates include security patterns FIRST
  • Critical patterns: .env*, credentials, keys, certificates
  • Regular security reviews and updates

2. Consistent Structure

  • Standardized headers with attribution
  • Clear metadata and usage notes
  • Logical section organization
  • Alphabetical sorting within sections

3. Comprehensive Coverage

  • Language-specific patterns
  • Framework-specific patterns
  • Build and cache directories
  • Testing and documentation files
  • IDE and tool configurations

4. Quality Assurance

  • No duplicate patterns
  • Tested with Docker builds
  • Validated against standards
  • Regular maintenance and updates

5. Clear Documentation

  • Usage notes and combination guidance
  • References to official sources
  • Best practices and recommendations
  • Examples and use cases

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines on:

  • Creating new templates
  • Improving existing templates
  • Reporting issues
  • Submitting pull requests
  • Testing and validation

Quick Contribution Steps

  1. Fork and Clone the repository
  2. Follow Standards in TEMPLATE_STANDARDS.md
  3. Test Thoroughly with Docker builds
  4. Submit Pull Request with clear description

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🌐 Website

Visit dockerignore.com for:

  • Interactive template browser
  • Custom .dockerignore generator
  • Documentation and examples
  • Community resources
  • Latest templates and updates

💖 Support

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

Community Resources


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

About

A collection of useful .dockerignore templates

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors