vstorm-co/production-stack-skills/production-docker
Claude Code and agent skill by vstorm-co/production-stack-skills
- community
Checking that the SKILL.md file is still in the repository.
Docker production hardening — multi-stage builds, non-root users, distroless images, BuildKit secrets, layer optimization, security scanning, and compose best practices. Use this skill when the user is creating or modifying Dockerfiles, docker-compose files, .dockerignore, or containerizing applications. Triggers on any Dockerfile, docker-compose.yml, .dockerignore, or when user mentions Docker, containers, or images. Also trigger when user says /production docker.
Install
npx vskill@latest install vstorm-co/production-stack-skills/production-dockerSKILL.md
The same SKILL.md was published earlier as vstorm-co/production-stack-skills/production-docker.
Production Docker Hardening
This skill transforms demo-quality Docker setups into production-grade container infrastructure. Every recommendation here comes from real incidents: breached containers running as root, 2GB images that take 8 minutes to deploy, secrets leaked into image layers. Follow this guide and none of that happens on your watch.
1. Multi-Stage Builds
Single-stage builds ship compilers, build tools, and source code to production. Multi-stage builds fix this by separating the build environment from the runtime environment.
Python example (builder + distroless):
Node.js example (builder + slim runtime):
Size impact: A typical Python app goes from ~1.2GB (python:3.12 with build deps) to ~120MB (distroless). That is a 90%+ reduction.
Rules:
- The builder stage installs dependencies and compiles code
- The runtime stage copies only the final artifacts
- Never install build tools (gcc, make, git) in the runtime stage
- Use
COPY --from=builderto cherry-pick what you need
2. Base Image Selection
Choose the smallest image that supports your runtime. Each option has tradeoffs:
| Image | Size | Shell | Package Manager | Use When | |
|---|---|---|---|---|---|
gcr.io/distroless/... | ~20-50MB | No | No | Production services, maximum security | |
alpine:3.x | ~7MB | Yes (ash) | apk | Need shell for debugging, musl is acceptable | |
python:3.12-slim / node:22-slim | ~150-200MB | Yes (bash) | apt | Need glibc compatibility, some native extensions | |
ubuntu:24.04 | ~75MB | Yes (bash) | apt | Complex native dependency chains |
Pinning rules:
- Pin by digest for reproducible builds:
FROM python:3.12-slim@sha256:abc123... - Pin by minor version at minimum:
FROM python:3.12-slim, neverFROM python:latest - Never use
latest— it is a moving target that breaks builds silently - Update digests on a schedule (monthly or via Dependabot/Renovate)
Distroless advantages:
- No shell means attackers who get code execution cannot spawn a shell
- No package manager means no installing tools post-exploitation
- Minimal filesystem reduces vulnerability surface to near zero
- CVE scan results are dramatically cleaner
3. Non-Root Execution
Running as root inside a container is the single most common Docker security mistake. If an attacker escapes the container with UID 0, they have root on the host.
Distroless (use the built-in nonroot user):
Debian/Ubuntu (create a dedicated user):
Alpine (create a dedicated user):
Rules:
- Set
USERas late as possible in the Dockerfile (after all installs and copies) - Use
--chownon COPY instructions to set correct ownership - Ensure the app directory and any writable paths are owned by the non-root user
- If the app needs to bind to port 80/443, use a reverse proxy or set
CAP_NET_BIND_SERVICE— do not run as root - Verify at runtime:
docker exec <container> whoamishould never returnroot
4. BuildKit Secrets
Secrets (API keys, tokens, private repo credentials) must never appear in image layers. Anyone with docker history or docker save can extract them.
The correct way — BuildKit secret mounts:
Build command:
For private git repos:
Build command:
What NEVER to do:
ARG MY_SECRET=...— visible indocker historyENV MY_SECRET=...— visible indocker inspectCOPY .env /app/.env— baked into a layer foreverCOPY id_rsa /root/.ssh/— private key in the image
Rule: If docker history --no-trunc <image> shows any secret value, the image is compromised and must be rebuilt.
5. Layer Optimization
Docker caches layers top-down. When a layer changes, all subsequent layers are invalidated. Order your Dockerfile to maximize cache hits.
Optimal layer order:
Rules:
- Copy dependency manifests (requirements.txt, package.json) before application code
- Install dependencies in a separate layer from code copying
- Combine related RUN commands with
&&to reduce layer count - Always clean up in the same layer:
apt-get install ... && rm -rf /var/lib/apt/lists/* - Use
--no-cache-dirwith pip to avoid caching wheels in the layer - Use
--no-compilewith pip to skip .pyc generation in the builder
6. .dockerignore
Without .dockerignore, COPY . . sends everything to the Docker daemon — including .git (potentially hundreds of MB), .env (secrets), node_modules, and test fixtures.
Mandatory exclusions:
Rules:
- Every project with a Dockerfile MUST have a .dockerignore
- Start restrictive, add exceptions with
!prefix as needed - Test with:
docker build --no-cache .and check context size in output - Context size over 50MB usually means .dockerignore is missing entries
7. Health Checks
Without health checks, Docker (and orchestrators) have no way to know if your app is actually serving requests. A container can be "running" with a completely hung process.
HTTP health check (preferred for web services):
For Node.js:
For distroless (no curl/wget):
Tuning guidelines:
--interval: 30s for most services, 10s for critical path--timeout: 5s usually sufficient; increase for services with slow health endpoints--start-period: Time for the app to boot. Set this generously (migrations, model loading)--retries: 3 is standard. Fewer for fast-failing services
Rules:
- Every production Dockerfile must have a HEALTHCHECK
- The health endpoint must verify real functionality (DB connection, not just "200 OK")
- Do not use
curlin distroless images (it does not exist) - Use the exec form
CMD ["..."]not shell formCMD ...
8. Security Scanning
Every image must be scanned before deployment. Trivy is the industry standard — it is fast, free, and catches CVEs in OS packages and language dependencies.
Local scan:
CI pipeline (fail the build on findings):
Rules:
- Scan in CI on every build — not just occasionally
- Set
--exit-code 1so builds fail on HIGH/CRITICAL findings - Use
--ignore-unfixedto suppress CVEs with no available fix - Pin the Trivy action/binary version for reproducible scans
- Scan both the builder stage and runtime stage if using multi-stage
- Maintain a
.trivyignorefile for accepted risks (with justification comments)
9. Compose Best Practices
Docker Compose for production requires explicit resource limits, health checks, and network isolation. The default "everything talks to everything" is a security problem.
Service dependencies with health checks:
Resource limits (prevent runaway containers):
Network isolation:
Rules:
- Always set
mem_limit/ deploy resource limits — a memory leak should not take down the host - Use
restart: unless-stoppedfor production services - Use named volumes for persistent data, never bind mounts in production
- Use
env_filefor environment variables, never hardcode secrets in compose files - Pin image tags in compose, same as Dockerfiles
- Separate compose files for dev vs production:
docker-compose.yml+docker-compose.prod.yml
10. Runtime Hardening
The image is only half the story. Runtime flags add defense-in-depth.
Read-only filesystem:
Drop capabilities:
No new privileges:
Docker run equivalent:
Rules:
- Start with
cap_drop: ALL, add back only what is needed no-new-privilegesprevents setuid binaries from escalating- Read-only filesystem forces you to explicitly declare writable paths
- Use
tmpfsfor directories that need to be writable (tmp, cache, pid files)
Anti-Patterns
This is the start of the file. Read the full SKILL.md on GitHub.
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/production-docker/SKILL.md
Popularity
- Repository stars
- 26
- Repository forks
- 7
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
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/vstorm-co/production-stack-skills/production-docker)