docker-management
Installation
SKILL.md
Docker Management
When to Load
Load this skill when the task involves Dockerfile authoring, Compose stack design, container registry operations, multi-stage build optimization, production container patterns, or troubleshooting container runtimes.
Core Concepts
Dockerfiles
- Multi-stage builds: Separate build-time dependencies from runtime image —
FROM ... AS builderfor compilation, finalFROMfor minimal runtime. Drastically reduces image size - Layer optimization: Each
RUN,COPY,ADDcreates a layer. Order from least-to-most frequently changing (system deps first, app code last). CombineRUN apt-get update && apt-get install -y ... && rm -rf /var/lib/apt/lists/*in one RUN to avoid caching stale package lists - Best practices: Use specific base image tags (not
:latest),COPY --chownfor non-root user,HEALTHCHECKinstruction,LABELfor metadata,EXPOSEfor documentation,ENTRYPOINT+CMDpattern for flexible default commands,.dockerignorefor build context size
Docker Compose
- Service definition:
image(build locally or pull),build(context + Dockerfile + args),ports,volumes,environment,depends_on,healthcheck,restart,networks - Production concerns: Named volumes (not bind mounts for persistent data), network isolation (separate frontend/backend/db networks), restart policies (
unless-stopped), CPU/memory limits (deploy.resources), logging driver (json-filewith rotation, orjournald) - Multi-file compose:
docker-compose -f docker-compose.yml -f docker-compose.prod.yml configfor override layers,docker-compose.yml(base) +docker-compose.override.yml(dev, gitignored) by convention