docker
Installation
SKILL.md
Docker & Containerization Skill
Roadmap Alignment: roadmap.sh/docker Reference: Docker Documentation
Core Standards (Effective Software Developer)
When writing or reviewing Dockerfiles and docker-compose.yml configurations, ensure they adhere to modern containerization best practices.
1. Dockerfile Best Practices
- Base Images: Always use official, minimal base images (e.g.,
alpine,slim, ordistroless) to reduce attack surface and download size. Pin specific versions (e.g.,node:18-alpineinstead ofnode:latest). - Multi-Stage Builds: Use multi-stage builds to separate build dependencies from runtime execution. Never ship source code, compilers, or test dependencies in a production image.
- Layer Caching: Order commands from least likely to change to most likely to change. Copy dependency files (like
package.jsonorGemfile) and install dependencies before copying the rest of the source code. - Non-Root User: Never run containers as the
rootuser in production. Always create a dedicated user and switch to it using theUSERinstruction. - Environment Variables: Use
ENVto set defaults, but prefer passing secrets at runtime. Avoid hardcoding credentials in the Dockerfile. - Graceful Shutdown: Handle
SIGTERMproperly. UseCMD ["executable", "param1"](exec form) rather thanCMD command param1(shell form) so the process receives signals correctly.