Docker patterns
Container build, security, and caching conventions. Use when editing Dockerfiles, Compose files, build contexts, or .dockerignore.From its SKILL.md
npx -y skills add edjchapman/claude-code-config --skill docker-patternsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 8 stars8 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
1.9 KB, as published. Nobody here has run it
Docker Patterns
Multi-Stage Builds
- Use multi-stage builds to separate build dependencies from runtime
- Name stages for clarity:
FROM node:20 AS builder - Copy only build artifacts into the final stage
- Keep the final image as small as possible (use
slimoralpinebase images)
Layer Caching
- Order instructions from least to most frequently changing
- Copy dependency files (
package.json,requirements.txt) before source code - Group related
RUNcommands with&&to reduce layers - Use
.dockerignoreto exclude unnecessary files from build context
.dockerignore
- Always include:
.git,node_modules,__pycache__,.env,*.log - Mirror
.gitignorepatterns plus build artifacts - Exclude test files and documentation from production images
Security
- Never run as root -- use
USER nonrootor create a dedicated user - Don't store secrets in images -- use environment variables or secrets managers
- Pin base image versions:
python:3.12-slimnotpython:latest - Scan images for vulnerabilities with
docker scoutortrivy - Use
COPYinstead ofADDunless you need tar extraction
Health Checks
- Always define
HEALTHCHECKin production Dockerfiles - Use lightweight endpoints (
/healthz) that check actual dependencies - Set appropriate intervals, timeouts, and retries
- Health checks should complete quickly (< 5s)
Compose Best Practices
- Use named volumes for persistent data
- Define explicit networks for service isolation
- Use
depends_onwith health check conditions - Use
.envfiles for environment configuration - Define resource limits (
mem_limit,cpus) for production - Use
profilesto group services by environment (dev, test, prod)