Skip to content

ronald2wing/.dockerignore

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.

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/nodejs.dockerignore

Visit Website

dockerignore.com - Browse templates and generate custom .dockerignore files.

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

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!

Template Categories

🏗️ Framework Templates (46 templates)

Self-contained, security-first templates for specific frameworks

  • Location: frameworks/
  • Examples: react.dockerignore, django.dockerignore, spring-boot.dockerignore
  • Usage: Use standalone - includes security patterns first

💻 Language Templates (21 templates)

Language-specific patterns for modular combination

  • Location: languages/
  • Examples: nodejs.dockerignore, python.dockerignore, java.dockerignore
  • Usage: Combine with common templates

🛡️ Common Templates (7 templates)

Cross-cutting concerns for all projects

  • Location: common/
  • Examples: security.dockerignore, cache.dockerignore, logs.dockerignore
  • Usage: Combine with language templates

🛠️ Tool Templates (6 templates)

Build and deployment tool patterns

  • Location: tools/
  • Examples: vite.dockerignore, webpack.dockerignore, vercel.dockerignore

💻 IDE Templates (4 templates)

Editor and IDE configuration files

  • Location: ides/
  • Examples: visual-studio-code.dockerignore, intellij.dockerignore

🖥️ OS Templates (3 templates)

Operating system-specific files

  • Location: os/
  • Examples: linux.dockerignore, macos.dockerignore, windows.dockerignore

How to Use Templates

Using Framework Templates (Recommended)

# Single framework template (self-contained)
cp frameworks/react.dockerignore .dockerignore

Combining Language and Common Templates

# Combine language with common templates
cat languages/python.dockerignore \
    common/security.dockerignore \
    common/cache.dockerignore > .dockerignore

Creating Custom Combinations

# Example: Python web project
cat languages/python.dockerignore \
    common/security.dockerignore \
    common/cache.dockerignore \
    common/logs.dockerignore \
    tools/docker.dockerignore > .dockerignore

Best Practices

1. Always Include Security Patterns

# Always include security patterns in your .dockerignore
cat common/security.dockerignore >> .dockerignore

2. Test Your .dockerignore File

# Test what files are being excluded
docker build --no-cache . 2>&1 | grep -i "sending\|context"

3. Remove Duplicate Patterns

# Remove duplicate patterns when combining templates
cat template1 template2 | sort -u > .dockerignore

4. Keep It Updated

  • Review your .dockerignore file quarterly
  • Update when adding new tools or dependencies
  • Remove patterns for tools you no longer use

5. Use Framework Templates When Possible

Framework templates are self-contained and include:

  • Security patterns first
  • Language-specific patterns
  • Framework-specific patterns
  • Build and cache directories

FAQ

Q: Should I use framework templates or language templates?

A: Use framework templates for framework-based projects (React, Django, 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

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.

Template Standards

All templates follow strict standards defined in TEMPLATE_STANDARDS.md:

  1. Security-first approach - Framework templates include security patterns first
  2. Consistent structure - Standardized headers and organization
  3. Alphabetical sorting - Patterns sorted within sections
  4. Clear documentation - Usage notes and combination guidance
  5. No duplicates - Each pattern appears only once

Contributing

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

  • Creating new templates
  • Improving existing templates
  • Reporting issues
  • Submitting pull requests

Documentation

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

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

Optimize your Docker builds today with comprehensive .dockerignore templates!

About

A collection of useful .dockerignore templates

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published