docker-conventions
Installation
SKILL.md
Docker and Containerization Best Practices
Follow these conventions when creating or modifying Dockerfiles, docker-compose files, and container configurations to produce images that are secure, efficient, and portable.
Core Principles
Four principles guide every containerization decision:
- Immutability. Build a new image for every change. Never patch running containers in place. Tag images with semantic versions (
v1.2.3) -- not justlatest-- so every deployment is traceable and rollbacks are straightforward. - Portability. Design images to run identically across dev, staging, and production. Inject environment-specific values at runtime through environment variables or mounted config files, never bake them into the image.
- Isolation. Run one process per container. This keeps logging, scaling, health checking, and resource management simple. Use container networking to connect services instead of running multiple processes in a single container.
- Efficiency. Smaller images build faster, transfer faster, and expose less attack surface. Every layer, package, and file you add is something an attacker could exploit and a developer must wait for.
Dockerfile Best Practices
Multi-Stage Builds
Multi-stage builds are the single most impactful Dockerfile technique. They separate the build environment (compilers, SDKs, dev dependencies) from the runtime image, often cutting image size by 80% or more.