100 Docker & Containers resources for developers
This resource guide provides actionable patterns and tools for optimizing Docker workflows, focusing on building slim, secure images and managing complex local development environments with Docker Compose.
Dockerfile Optimization and Build Patterns
- 1
Implement Multi-Stage Builds
beginnerhighSeparate build-time dependencies from the final runtime image using 'FROM ... AS build' and 'COPY --from=build' to reduce image size by up to 90%.
- 2
BuildKit Cache Mounts
intermediatehighUse 'RUN --mount=type=cache,target=/root/.npm' to persist package manager caches between builds, significantly reducing CI/CD build times.
- 3
Distroless Runtime Images
advancedhighUse GoogleContainerTools/distroless as the final stage base to remove shells and package managers, minimizing the attack surface.
- 4
Layer Ordering for Caching
beginnerstandardCopy dependency files (package.json, go.mod) and run install commands before copying the rest of the source code to maximize layer reuse.
- 5
Hadolint for Linting
beginnermediumIntegrate Hadolint into your CI pipeline to enforce Dockerfile best practices and catch inefficient instructions like 'RUN apt-get upgrade'.
- 6
Non-Root User Configuration
intermediatehighExplicitly create a system user and use the 'USER' instruction to avoid running container processes as root, preventing container breakout exploits.
- 7
Tini Init Process
intermediatestandardUse 'tini' as your entrypoint to correctly handle signal forwarding and reap zombie processes in containers running complex applications.
- 8
.dockerignore Optimization
beginnermediumExclude .git, node_modules, and local build artifacts to prevent sending unnecessary context to the Docker daemon and bloating layers.
- 9
Specific Tag Versioning
beginnerhighAvoid the ':latest' tag; use specific semantic versions or SHA256 hashes for base images to ensure build reproducibility across environments.
- 10
Dive Layer Inspection
intermediatemediumUse the 'dive' CLI tool to analyze image layers and identify wasted space or files that should have been excluded from the final image.
Docker Compose and Local Development
- 1
Healthcheck-based Dependencies
intermediatehighUse 'depends_on' with 'condition: service_healthy' to ensure the application only starts after the database is ready to accept connections.
- 2
Docker Compose Profiles
intermediatemediumDefine 'profiles' in your YAML to selectively start services, such as 'debug' or 'testing' tools, without cluttering the default stack.
- 3
Bind Mounts for Hot Reload
beginnerhighMap local source directories to container paths using volumes to enable live-reloading frameworks (like Vite or Nodemon) without rebuilding.
- 4
Environment Variable Files
beginnerstandardUtilize '.env' files alongside 'env_file' directives to manage secrets and configurations locally without hardcoding values in the YAML.
- 5
External Network Isolation
intermediatemediumDefine external networks to allow communication between separate Compose projects while keeping database traffic isolated from the public bridge.
- 6
Resource Constraints
intermediatestandardApply 'deploy.resources.limits' in Compose files to simulate production constraints (CPU/Memory) and prevent local resource exhaustion.
- 7
Traefik Reverse Proxy Integration
advancedhighRun Traefik in a container to provide automatic SSL and local domain routing (e.g., app.localhost) for multiple Compose services.
- 8
Docker Compose Overrides
beginnermediumUse 'docker-compose.override.yml' for local-only settings like debug ports, keeping the base YAML clean for production-like environments.
- 9
Named Volumes for Persistence
beginnerhighUse named volumes instead of host paths for database data to improve I/O performance on macOS and Windows via VirtioFS.
- 10
Lazydocker TUI
beginnermediumManage containers, logs, and resource usage from the terminal using 'lazydocker' for faster troubleshooting than the standard CLI.
Container Security and Operations
- 1
Trivy Vulnerability Scanning
intermediatehighRun 'trivy image <name>' in your CI pipeline to detect CVEs in OS packages and application dependencies before deployment.
- 2
Read-Only Root Filesystem
advancedhighSet 'read_only: true' in Compose or '--read-only' in CLI to prevent attackers from writing malicious scripts to the container's disk.
- 3
Log Rotation Configuration
beginnerstandardConfigure the 'json-file' logging driver with 'max-size' and 'max-file' limits to prevent container logs from consuming all host disk space.
- 4
Seccomp Profile Hardening
advancedmediumApply custom Seccomp profiles to restrict the system calls a container can make, mitigating kernel-level exploits.
- 5
Docker Scout SBOM
intermediatemediumGenerate a Software Bill of Materials (SBOM) using Docker Scout to track exactly which software versions are running in production.
- 6
Automated Image Pruning
beginnerstandardSchedule 'docker system prune -af --volumes' via cron to remove dangling images and unused networks that accumulate on build nodes.
- 7
GHCR Authenticated Pulls
intermediatehighConfigure GitHub Actions to use 'docker/login-action' with temporary GITHUB_TOKEN for secure image pushes to GitHub Container Registry.
- 8
Portainer Environment Management
beginnermediumDeploy Portainer as a lightweight management UI to visualize container health and manage remote Docker engines via an agent.
- 9
Watchtower Auto-Updates
intermediatestandardUse the Watchtower container to automatically pull the latest images and restart containers when a new version is pushed to the registry.
- 10
Container Resource Monitoring
advancedmediumDeploy cAdvisor to collect real-time resource usage and performance characteristics of running containers for Prometheus scraping.