skills/docker/SKILL.md
Docker containerization — Dockerfile, multi-stage builds, Docker Compose, image size optimization, security scanning, networking, volumes.
npx skillsauth add arbazkhan971/godmode dockerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
/godmode:docker/godmode:reviewUnderstand the project and its containerization needs:
DOCKER CONTEXT ASSESSMENT:
Project:
Language/Runtime: <Node.js | Python | Go | Java | Rust | multi-language>
Framework: <Express | Django | Spring | etc.>
Build system: <npm | pip | gradle | cargo | make>
Entry point: <main file or command>
Current Docker state:
Dockerfile: <exists | missing | multiple>
Docker Compose: <exists | missing>
.dockerignore: <exists | missing | incomplete>
Base image: <image:tag>
Image size: <current size>
Build time: <current build time>
Layers: <number of layers>
Create or optimize the Dockerfile using production-grade patterns:
# --- Stage 1: Dependencies (cached separately from source code)
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --only=production
# --- Stage 2: Build (compile/transpile source code)
FROM node:20-alpine AS build
WORKDIR /app
LAYER CACHING RULES:
| Rule | Why |
|--|--|
| COPY dependency files first | Dependencies change less |
| | often than source code |
| RUN install BEFORE COPY src | Bust cache only when deps |
| | actually change |
| Order instructions by change | Least-changing layers first, |
| frequency | most-changing layers last |
| Combine related RUN commands | Fewer layers, smaller image |
| Use .dockerignore | Exclude node_modules, .git, |
| | test files from build context |
MULTI-STAGE BUILD BY LANGUAGE:
| Language | Build Image | Runtime Image | Size |
|--|--|--|--|
| Node.js | node:20-alpine | node:20-alpine | ~120MB |
| Python | python:3.12-slim | python:3.12-slim | ~150MB |
| Go | golang:1.22-alpine | scratch/distroless | ~10MB |
| Rust | rust:1.77-alpine | scratch/distroless | ~5MB |
| Java | eclipse-temurin:21 | eclipse-temurin: | ~200MB |
| | | 21-jre-alpine | |
| .NET | mcr.microsoft.com/ | mcr.microsoft.com | ~100MB |
| | dotnet/sdk:8.0 | /dotnet/aspnet: | |
| | | 8.0-alpine | |
Set up a complete local development environment:
# docker-compose.yml — Local development
version: "3.9"
services:
app:
build:
DOCKER COMPOSE PATTERNS:
| Pattern | Purpose |
|--|--|
| depends_on + health | Start order with readiness check |
| target: development | Use dev stage of multi-stage build |
| bind mount + anon vol | Hot reload without overwriting deps |
| named volumes | Persist data across restarts |
| profiles | Optional services (monitoring, debug) |
| env_file | Keep secrets out of compose file |
Reduce image size systematically:
IMAGE SIZE OPTIMIZATION CHECKLIST:
| Technique | Typical Savings |
|--|--|
| Multi-stage build | 50-90% reduction |
| Alpine/distroless base | 60-80% vs debian/ubuntu |
| .dockerignore (exclude .git, | 10-50% build context |
| node_modules, tests, docs) | reduction |
| Combine RUN commands | 5-20% fewer layers |
| Remove package manager cache | 10-50MB savings |
| (rm -rf /var/cache/apk/*) | |
| --no-install-recommends (apt) | 10-30% package reduction |
| npm ci --only=production | 30-70% node_modules |
| Strip debug symbols (Go/Rust) | 20-40% binary size |
| UPX compression (Go/Rust) | 50-70% binary size |
Scan images for vulnerabilities and apply security best practices:
SECURITY SCANNING TOOLS:
| Tool | Command |
|--|--|
| Trivy | trivy image <image:tag> |
| Snyk | snyk container test <image:tag> |
| Docker Scout | docker scout cves <image:tag> |
| Grype | grype <image:tag> |
| Dockle | dockle <image:tag> |
TRIVY SCANNING (recommended):
# Scan for vulnerabilities
trivy image --severity HIGH,CRITICAL <image:tag>
Configure networking and persistent storage:
DOCKER NETWORKING:
| Network Type | Use Case |
|--|--|
| bridge (default) | Containers on same host communicate |
| host | Container shares host network (no isolation) |
| overlay | Multi-host communication (Swarm/K8s) |
| macvlan | Container gets its own MAC address |
| none | No networking (isolated workloads) |
COMPOSE NETWORKING PATTERNS:
# Isolated networks for microservices
networks:
frontend: # Public-facing services
Use advanced build capabilities:
BUILDKIT FEATURES:
| Feature | Syntax / Usage |
|--|--|
| Enable BuildKit | DOCKER_BUILDKIT=1 docker build . |
| Cache mounts | RUN --mount=type=cache,target=/root |
| | /.cache/pip pip install -r req.txt |
| Secret mounts | RUN --mount=type=secret,id=mysecret |
| | cat /run/secrets/mysecret |
| SSH mounts | RUN --mount=type=ssh git clone ... |
| Heredocs | RUN <<EOF |
| | apt-get update |
| | apt-get install -y curl |
| | EOF |
| Multi-platform builds | docker buildx build --platform |
DOCKER CONFIGURATION REPORT
Dockerfile: <created | optimized | validated>
Build type: <single-stage | multi-stage>
Base image: <image:tag>
Final image size: <size>
Layers: <N>
Docker Compose: <created | updated | N/A>
Services: <list>
Volumes: <list>
Networks: <list>
Security:
"build(docker): Dockerfile — multi-stage <language> with <base image>""build(docker): docker-compose — <N services> for local dev"/godmode:k8s for Kubernetes deployment or /godmode:deploy to ship."Never ask to continue. Loop autonomously until done.
# Docker diagnostics
docker build --target test -t myapp:test .
docker images myapp --format "table {{.Tag}}\t{{.Size}}"
trivy image --severity CRITICAL,HIGH myapp:latest
docker history myapp:latest --no-trunc | head -20
IF image size > 200MB (Node/Python) or > 50MB (Go/Rust): optimize with multi-stage and alpine. WHEN trivy reports > 0 CRITICAL CVEs: update base image before deploying. IF build time > 5 minutes: audit layer caching order and .dockerignore.
| Flag | Description |
|--|--|
| (none) | Full Docker assessment and optimization |
| --init | Create Dockerfile and Compose from scratch |
| --optimize | Optimize existing Docker configuration |
latest tag for base images — pin to specific version (e.g., node:20.11-alpine)KEEP if: image size decreased AND 0 new CVEs AND container starts successfully
DISCARD if: image size increased OR new critical CVE OR container fails to start
Never keep a size optimization that introduces a critical CVE.
STOP when: multi-stage + non-root + healthcheck + 0 critical CVEs + size within target.
Targets: Go <50MB, Node <200MB, Python <200MB. Max 10 iterations.
On failure: git reset --hard HEAD~1.
1. Scan for Dockerfile*, docker-compose*, .dockerignore
2. Detect language: package.json→Node, pyproject.toml→Python, go.mod→Go, Cargo.toml→Rust
3. Check image quality: FROM tag, USER, HEALTHCHECK, multi-stage. State: missing | unoptimized | production-ready
Print on completion: Docker: {image_count} images optimized. Size: {before_size} → {after_size} (-{savings}%). Layers: {layer_count}. Security: {vuln_count} vulnerabilities ({critical} critical). Build: {build_time}. Verdict: {verdict}.
Log to .godmode/docker-results.tsv:
iteration image size_before size_after layers vulns_critical vulns_high build_time_s status
| Failure | Action |
|--|--|
| Build fails at install | Verify lockfile copied before install. Check base image deps. |
| Image too large | docker history --no-trunc. Check multi-stage + .dockerignore. |
| Container crashes | Check docker logs, CMD/ENTRYPOINT, non-root permissions. |
| Health check fails | Verify endpoint, --start-period, health tool in image. |
| Critical CVEs | Update base image tag. If no fix, document accepted risk. |
development
Web performance optimization. Lighthouse, bundle analysis, code splitting, image optimization, critical CSS, fonts, service workers, CDN.
development
Webhook design, delivery, retry, HMAC verification, event subscriptions, dead letter queues.
development
Vue.js mastery. Composition API, Pinia, Vue Router, Nuxt SSR/SSG, Vite optimization, testing.
development
Evidence gate. Run command, read full output, confirm or deny claim. No trust, only proof.