1mangesh1/dev-skills-collection/containerization-best-practices
Claude Code and agent skill by 1mangesh1/dev-skills-collection
- community
Checking that the SKILL.md file is still in the repository.
Container and Docker best practices for production workloads. Use when user asks to "optimize Docker", "Docker best practices", "container security", "image optimization", "layer caching", "multi-stage builds", "container networking", "volume management", "Docker performance", "reduce image size", "container hardening", "Dockerfile lint", "health checks", "graceful shutdown", "container debugging", "resource limits", "distroless", "tini init", "container logging", or mentions containerization strategies and Docker optimization.
Install
npx vskill@latest install 1mangesh1/dev-skills-collection/containerization-best-practicesSKILL.md
Containerization & Docker Best Practices
Production-grade Docker and containerization strategies for building efficient, secure, and maintainable containers.
Dockerfile Best Practices
Layer Ordering
Order instructions from least to most frequently changing. System deps first, then app deps, then source code. Each instruction creates a layer. Docker caches layers top-down and invalidates everything below a changed layer.
Multi-Stage Builds
Separate build-time dependencies from runtime. Only copy artifacts you need.
For statically linked binaries (Go, Rust), use scratch or gcr.io/distroless/static-debian12 as the final stage for minimal images (~2MB).
.dockerignore
Reduces build context size and prevents secrets from leaking into images.
Base Image Selection
| Image | Size | Shell | Use Case | |
|---|---|---|---|---|
node:20 | ~350MB | Yes | Avoid in prod | |
node:20-slim | ~200MB | Yes | Good default | |
node:20-alpine | ~50MB | Yes | Best for most apps | |
distroless | ~2-20MB | No | Maximum security |
Pin Versions
Never use latest in production. Pin to patch version, or digest for full reproducibility.
Security Hardening
Non-Root User
Read-Only Filesystem
No Secrets in Images
Secrets in Dockerfile instructions persist in layer history.
Image Scanning
Drop Capabilities
Layer Caching Optimization
Dependency Install Before Code Copy
Copy manifests first, install, then copy source. This is the single most impactful caching rule.
BuildKit Cache Mounts
Persist package manager caches across builds.
Enable BuildKit: export DOCKER_BUILDKIT=1
Health Checks
Compose Health Checks with Dependencies
Container Networking
Containers on user-defined bridge networks get DNS resolution by container name. The default bridge network does not provide this.
Volume Management
Logging Best Practices
Applications should write to stdout/stderr, never to files inside the container.
Set defaults in daemon.json: { "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "5" } }
Resource Limits
Compose Resource Limits
Debugging Containers
Production Patterns
Graceful Shutdown and Signal Handling
Containers receive SIGTERM on stop. The app must handle it or Docker sends SIGKILL after the grace period (default 10s). Always use exec form so the app is PID 1.
Init System with Tini
Use tini as PID 1 to reap zombie processes and forward signals.
Or: docker run --init myapp:latest
Stop Grace Period
Image Size Reduction
- Multi-stage builds to exclude compilers and build tools
- Alpine or distroless base images
- Combine RUN commands to reduce layers
- Remove caches in the same layer they are created
- Use
--no-install-recommends(apt) or--no-cache(apk)
Container Orchestration Considerations
Labels and Metadata
Docker Compose Production Stack
Image Registry
References
- Docker Best Practices: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
- Distroless Images: https://github.com/GoogleContainerTools/distroless
- Trivy Scanner: https://github.com/aquasecurity/trivy
- Tini Init: https://github.com/krallin/tini
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/containerization-best-practices/SKILL.md
Popularity
- Repository stars
- 2
- 7-day trend score
- 5
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 24 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/1mangesh1/dev-skills-collection/containerization-best-practices)