Docker Development
Smaller images. Faster builds. Secure containers. No guesswork.
Opinionated Docker workflow that turns bloated Dockerfiles into production-grade containers. Covers optimization, multi-stage builds, compose orchestration, and security hardening.
Not a Docker tutorial — a set of concrete decisions about how to build containers that don't waste time, space, or attack surface.
Slash Commands
| Command |
What it does |
/docker:optimize |
Analyze and optimize a Dockerfile for size, speed, and layer caching |
/docker:compose |
Generate or improve docker-compose.yml with best practices |
/docker:security |
Audit a Dockerfile or running container for security issues |
When This Skill Activates
Recognize these patterns from the user:
- "Optimize this Dockerfile"
- "My Docker build is slow"
- "Create a docker-compose for this project"
- "Is this Dockerfile secure?"
- "Reduce my Docker image size"
- "Set up multi-stage builds"
- "Docker best practices for [language/framework]"
- Any request involving: Dockerfile, docker-compose, container, image size, build cache, Docker security
If the user has a Dockerfile or wants to containerize something → this skill applies.
Workflow
/docker:optimize — Dockerfile Optimization
Analyze current state
- Read the Dockerfile
- Identify base image and its size
- Count layers (each RUN/COPY/ADD = 1 layer)
- Check for common anti-patterns
Apply optimization checklist
BASE IMAGE
├── Use specific tags, never :latest in production
├── Prefer slim/alpine variants (debian-slim > ubuntu > debian)
├── Pin digest for reproducibility in CI: image@sha256:...
└── Match base to runtime needs (don't use python:3.12 for a compiled binary)
LAYER OPTIMIZATION
├── Combine related RUN commands with && \
├── Order layers: least-changing first (deps before source code)
├── Clean package manager cache in the same RUN layer
├── Use .dockerignore to exclude unnecessary files
└── Separate build deps from runtime deps
BUILD CACHE
├── COPY dependency files before source code (package.json, requirements.txt, go.mod)
├── Install deps in a separate layer from code copy
├── Use BuildKit cache mounts: --mount=type=cache,target=/root/.cache
└── Avoid COPY . . before dependency installation
MULTI-STAGE BUILDS
├── Stage 1: build (full SDK, build tools, dev deps)
├── Stage 2: runtime (minimal base, only production artifacts)
├── COPY --from=builder only what's needed
└── Final image should have NO build tools, NO source code, NO dev deps
Generate optimized Dockerfile
- Apply all relevant optimizations
- Add inline comments explaining each decision
- Report estimated size reduction
Validate
python3 scripts/dockerfile_analyzer.py Dockerfile
Note: Bundled scripts ship as Markdown reference (.md) — copy the code out of the .md file to run it.
/docker:compose — Docker Compose Configuration
Identify services
- Application (web, API, worker)
- Database (postgres, mysql, redis, mongo)
- Cache (redis, memcached)
- Queue (rabbitmq, kafka)
- Reverse proxy (nginx, traefik, caddy)
Apply compose best practices
SERVICES
├── Use depends_on with condition: service_healthy
├── Add healthchecks for every service
├── Set resource limits (mem_limit, cpus)
├── Use named volumes for persistent data
└── Pin image versions
NETWORKING
├── Create explicit networks (don't rely on default)
├── Separate frontend and backend networks
├── Only expose ports that need external access
└── Use internal: true for backend-only networks
ENVIRONMENT
├── Use env_file for secrets, not inline environment
├── Never commit .env files (add to .gitignore)
├── Use variable substitution: ${VAR:-default}
└── Document all required env vars
DEVELOPMENT vs PRODUCTION
├── Use compose profiles or override files
├── Dev: bind mounts for hot reload, debug ports exposed
├── Prod: named volumes, no debug ports, restart: unless-stopped
└── docker-compose.override.yml for dev-only config
Generate compose file
- Output docker-compose.yml with healthchecks, networks, volumes
- Generate .env.example with all required variables documented
- Add dev/prod profile annotations
/docker:security — Container Security Audit
Dockerfile audit
| Check |
Severity |
Fix |
| Running as root |
Critical |
Add USER nonroot after creating user |
| Using :latest tag |
High |
Pin to specific version |
| Secrets in ENV/ARG |
Critical |
Use BuildKit secrets: --mount=type=secret |
| COPY with broad glob |
Medium |
Use specific paths, add .dockerignore |
| Unnecessary EXPOSE |
Low |
Only expose ports the app uses |
| No HEALTHCHECK |
Medium |
Add HEALTHCHECK with appropriate interval |
| Privileged instructions |
High |
Avoid --privileged, drop capabilities |
| Package manager cache retained |
Low |
Clean in same RUN layer |
Runtime security checks
| Check |
Severity |
Fix |
| Container running as root |
Critical |
Set user in Dockerfile or compose |
| Writable root filesystem |
Medium |
Use read_only: true in compose |
| All capabilities retained |
High |
Drop all, add only needed: cap_drop: [ALL] |
| No resource limits |
Medium |
Set mem_limit and cpus |
| Host network mode |
High |
Use bridge or custom network |
| Sensitive mounts |
Critical |
Never mount /etc, /var/run/docker.sock in prod |
| No log driver configured |
Low |
Set logging: with size limits |
Generate security report
SECURITY AUDIT — [Dockerfile/Image name]
Date: [timestamp]
CRITICAL: [count]
HIGH: [count]
MEDIUM: [count]
LOW: [count]
[Detailed findings with fix recommendations]
Tooling
scripts/dockerfile_analyzer.py.md
CLI utility for static analysis of Dockerfiles.
Features:
- Layer count and optimization suggestions
- Base image analysis with size estimates
- Anti-pattern detection (15+ rules)
- Security issue flagging
- Multi-stage build detection and validation
- JSON and text output
Usage:
# Analyze a Dockerfile
python3 scripts/dockerfile_analyzer.py Dockerfile
# JSON output
python3 scripts/dockerfile_analyzer.py Dockerfile --output json
# Analyze with security focus
python3 scripts/dockerfile_analyzer.py Dockerfile --security
# Check a specific directory
python3 scripts/dockerfile_analyzer.py path/to/Dockerfile
scripts/compose_validator.py.md
CLI utility for validating docker-compose files.
Features:
- Service dependency validation
- Healthcheck presence detection
- Network configuration analysis
- Volume mount validation
- Environment variable audit
- Port conflict detection
- Best practice scoring
Usage:
# Validate a compose file
python3 scripts/compose_validator.py docker-compose.yml
# JSON output
python3 scripts/compose_validator.py docker-compose.yml --output json
# Strict mode (fail on warnings)
python3 scripts/compose_validator.py docker-compose.yml --strict
Multi-Stage Build Patterns
Pattern 1: Compiled Language (Go, Rust, C++)
# Build stage
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app/server ./cmd/server
# Runtime stage
FROM gcr.io/distroless/static-debian12
COPY --from=builder /app/server /server
USER nonroot:nonroot
ENTRYPOINT ["/server"]
Pattern 2: Node.js / TypeScript
# Dependencies stage
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --production=false
# Build stage
FROM deps AS builder
COPY . .
RUN npm run build
# Runtime stage
FROM node:20-alpine
WORKDIR /app
RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001
COPY --from=builder /app/dist ./dist
COPY --from=deps /app/node_modules ./node_modules
COPY package.json ./
USER appuser
EXPOSE 3000
CMD ["node", "dist/index.js"]
Pattern 3: Python
# Build stage
FROM python:3.12-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# Runtime stage
FROM python:3.12-slim
WORKDIR /app
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
COPY --from=builder /install /usr/local
COPY . .
USER appuser
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
Base Image Decision Tree
Is it a compiled binary (Go, Rust, C)?
├── Yes → distroless/static or scratch
└── No
├── Need a shell for debugging?
│ ├── Yes → alpine variant (e.g., node:20-alpine)
│ └── No → distroless variant
├── Need glibc (not musl)?
│ ├── Yes → slim variant (e.g., python:3.12-slim)
│ └── No → alpine variant
└── Need specific OS packages?
├── Many → debian-slim
└── Few → alpine + apk add
Proactive Triggers
Flag these without being asked:
- Dockerfile uses :latest → Suggest pinning to a specific version tag.
- No .dockerignore → Create one. At minimum:
.git, node_modules, __pycache__, .env.
- COPY . . before dependency install → Cache bust. Reorder to install deps first.
- Running as root → Add USER instruction. No exceptions for production.
- Secrets in ENV or ARG → Use BuildKit secret mounts. Never bake secrets into layers.
- Image over 1GB → Multi-stage build required. No reason for a production image this large.
- No healthcheck → Add one. Orchestrators (Compose, K8s) need it for proper lifecycle management.
- apt-get without cleanup in same layer →
rm -rf /var/lib/apt/lists/* in the same RUN.
Installation
One-liner (any tool)
git clone https://github.com/alirezarezvani/claude-skills.git
cp -r claude-skills/engineering/docker-development ~/.claude/skills/
Multi-tool install
./scripts/convert.sh --skill docker-development --tool codex|gemini|cursor|windsurf|openclaw
OpenClaw
clawhub install cs-docker-development
Related Skills
- senior-devops — Broader DevOps scope (CI/CD, IaC, monitoring). Complementary — use docker-development for container-specific work, senior-devops for pipeline and infrastructure.
- senior-security — Application security. Complementary — docker-development covers container security, senior-security covers application-level threats.
- autoresearch-agent — Can optimize Docker build times or image sizes as measurable experiments.
- ci-cd-pipeline-builder — Pipeline construction. Complementary — docker-development builds the containers, ci-cd-pipeline-builder deploys them.
1---2name: docker-development3description: "Docker and container development agent skill and plugin for Dockerfile optimization, docker-compose orchestration, multi-stage builds, and container security hardening. Use when: user wants to optimize a Dockerfile, create or improve docker-compose configurations, implement multi-stage builds, audit container security, reduce image size, or follow container best practices. Covers build performance, layer caching, secret management, and production-ready container patterns."4license: MIT5metadata:6 source: https://skillmd.com/skills/neekware/docker-development7 version: 1.0.08 author: Alireza Rezvani9 category: engineering10 updated: 2026-03-1611---1213# Docker Development1415> Smaller images. Faster builds. Secure containers. No guesswork.1617Opinionated Docker workflow that turns bloated Dockerfiles into production-grade containers. Covers optimization, multi-stage builds, compose orchestration, and security hardening.1819Not a Docker tutorial — a set of concrete decisions about how to build containers that don't waste time, space, or attack surface.2021---2223## Slash Commands2425| Command | What it does |26| ------------------ | -------------------------------------------------------------------- |27| `/docker:optimize` | Analyze and optimize a Dockerfile for size, speed, and layer caching |28| `/docker:compose` | Generate or improve docker-compose.yml with best practices |29| `/docker:security` | Audit a Dockerfile or running container for security issues |3031---3233## When This Skill Activates3435Recognize these patterns from the user:3637- "Optimize this Dockerfile"38- "My Docker build is slow"39- "Create a docker-compose for this project"40- "Is this Dockerfile secure?"41- "Reduce my Docker image size"42- "Set up multi-stage builds"43- "Docker best practices for [language/framework]"44- Any request involving: Dockerfile, docker-compose, container, image size, build cache, Docker security4546If the user has a Dockerfile or wants to containerize something → this skill applies.4748---4950## Workflow5152### `/docker:optimize` — Dockerfile Optimization53541. **Analyze current state**55 - Read the Dockerfile56 - Identify base image and its size57 - Count layers (each RUN/COPY/ADD = 1 layer)58 - Check for common anti-patterns59602. **Apply optimization checklist**6162 ```63 BASE IMAGE64 ├── Use specific tags, never :latest in production65 ├── Prefer slim/alpine variants (debian-slim > ubuntu > debian)66 ├── Pin digest for reproducibility in CI: image@sha256:...67 └── Match base to runtime needs (don't use python:3.12 for a compiled binary)6869 LAYER OPTIMIZATION70 ├── Combine related RUN commands with && \71 ├── Order layers: least-changing first (deps before source code)72 ├── Clean package manager cache in the same RUN layer73 ├── Use .dockerignore to exclude unnecessary files74 └── Separate build deps from runtime deps7576 BUILD CACHE77 ├── COPY dependency files before source code (package.json, requirements.txt, go.mod)78 ├── Install deps in a separate layer from code copy79 ├── Use BuildKit cache mounts: --mount=type=cache,target=/root/.cache80 └── Avoid COPY . . before dependency installation8182 MULTI-STAGE BUILDS83 ├── Stage 1: build (full SDK, build tools, dev deps)84 ├── Stage 2: runtime (minimal base, only production artifacts)85 ├── COPY --from=builder only what's needed86 └── Final image should have NO build tools, NO source code, NO dev deps87 ```88893. **Generate optimized Dockerfile**90 - Apply all relevant optimizations91 - Add inline comments explaining each decision92 - Report estimated size reduction93944. **Validate**95 ```bash96 python3 scripts/dockerfile_analyzer.py Dockerfile97 ```9899> **Note:** Bundled scripts ship as Markdown reference (`.md`) — copy the code out of the `.md` file to run it.100101### `/docker:compose` — Docker Compose Configuration1021031. **Identify services**104 - Application (web, API, worker)105 - Database (postgres, mysql, redis, mongo)106 - Cache (redis, memcached)107 - Queue (rabbitmq, kafka)108 - Reverse proxy (nginx, traefik, caddy)1091102. **Apply compose best practices**111112 ```113 SERVICES114 ├── Use depends_on with condition: service_healthy115 ├── Add healthchecks for every service116 ├── Set resource limits (mem_limit, cpus)117 ├── Use named volumes for persistent data118 └── Pin image versions119120 NETWORKING121 ├── Create explicit networks (don't rely on default)122 ├── Separate frontend and backend networks123 ├── Only expose ports that need external access124 └── Use internal: true for backend-only networks125126 ENVIRONMENT127 ├── Use env_file for secrets, not inline environment128 ├── Never commit .env files (add to .gitignore)129 ├── Use variable substitution: ${VAR:-default}130 └── Document all required env vars131132 DEVELOPMENT vs PRODUCTION133 ├── Use compose profiles or override files134 ├── Dev: bind mounts for hot reload, debug ports exposed135 ├── Prod: named volumes, no debug ports, restart: unless-stopped136 └── docker-compose.override.yml for dev-only config137 ```1381393. **Generate compose file**140 - Output docker-compose.yml with healthchecks, networks, volumes141 - Generate .env.example with all required variables documented142 - Add dev/prod profile annotations143144### `/docker:security` — Container Security Audit1451461. **Dockerfile audit**147148 | Check | Severity | Fix |149 | ------------------------------ | -------- | ------------------------------------------- |150 | Running as root | Critical | Add `USER nonroot` after creating user |151 | Using :latest tag | High | Pin to specific version |152 | Secrets in ENV/ARG | Critical | Use BuildKit secrets: `--mount=type=secret` |153 | COPY with broad glob | Medium | Use specific paths, add .dockerignore |154 | Unnecessary EXPOSE | Low | Only expose ports the app uses |155 | No HEALTHCHECK | Medium | Add HEALTHCHECK with appropriate interval |156 | Privileged instructions | High | Avoid `--privileged`, drop capabilities |157 | Package manager cache retained | Low | Clean in same RUN layer |1581592. **Runtime security checks**160161 | Check | Severity | Fix |162 | ------------------------- | -------- | ---------------------------------------------- |163 | Container running as root | Critical | Set user in Dockerfile or compose |164 | Writable root filesystem | Medium | Use `read_only: true` in compose |165 | All capabilities retained | High | Drop all, add only needed: `cap_drop: [ALL]` |166 | No resource limits | Medium | Set `mem_limit` and `cpus` |167 | Host network mode | High | Use bridge or custom network |168 | Sensitive mounts | Critical | Never mount /etc, /var/run/docker.sock in prod |169 | No log driver configured | Low | Set `logging:` with size limits |1701713. **Generate security report**172173 ```174 SECURITY AUDIT — [Dockerfile/Image name]175 Date: [timestamp]176177 CRITICAL: [count]178 HIGH: [count]179 MEDIUM: [count]180 LOW: [count]181182 [Detailed findings with fix recommendations]183 ```184185---186187## Tooling188189### `scripts/dockerfile_analyzer.py.md`190191CLI utility for static analysis of Dockerfiles.192193**Features:**194195- Layer count and optimization suggestions196- Base image analysis with size estimates197- Anti-pattern detection (15+ rules)198- Security issue flagging199- Multi-stage build detection and validation200- JSON and text output201202**Usage:**203204```bash205# Analyze a Dockerfile206python3 scripts/dockerfile_analyzer.py Dockerfile207208# JSON output209python3 scripts/dockerfile_analyzer.py Dockerfile --output json210211# Analyze with security focus212python3 scripts/dockerfile_analyzer.py Dockerfile --security213214# Check a specific directory215python3 scripts/dockerfile_analyzer.py path/to/Dockerfile216```217218### `scripts/compose_validator.py.md`219220CLI utility for validating docker-compose files.221222**Features:**223224- Service dependency validation225- Healthcheck presence detection226- Network configuration analysis227- Volume mount validation228- Environment variable audit229- Port conflict detection230- Best practice scoring231232**Usage:**233234```bash235# Validate a compose file236python3 scripts/compose_validator.py docker-compose.yml237238# JSON output239python3 scripts/compose_validator.py docker-compose.yml --output json240241# Strict mode (fail on warnings)242python3 scripts/compose_validator.py docker-compose.yml --strict243```244245---246247## Multi-Stage Build Patterns248249### Pattern 1: Compiled Language (Go, Rust, C++)250251```dockerfile252# Build stage253FROM golang:1.22-alpine AS builder254WORKDIR /app255COPY go.mod go.sum ./256RUN go mod download257COPY . .258RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app/server ./cmd/server259260# Runtime stage261FROM gcr.io/distroless/static-debian12262COPY --from=builder /app/server /server263USER nonroot:nonroot264ENTRYPOINT ["/server"]265```266267### Pattern 2: Node.js / TypeScript268269```dockerfile270# Dependencies stage271FROM node:20-alpine AS deps272WORKDIR /app273COPY package.json package-lock.json ./274RUN npm ci --production=false275276# Build stage277FROM deps AS builder278COPY . .279RUN npm run build280281# Runtime stage282FROM node:20-alpine283WORKDIR /app284RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001285COPY --from=builder /app/dist ./dist286COPY --from=deps /app/node_modules ./node_modules287COPY package.json ./288USER appuser289EXPOSE 3000290CMD ["node", "dist/index.js"]291```292293### Pattern 3: Python294295```dockerfile296# Build stage297FROM python:3.12-slim AS builder298WORKDIR /app299COPY requirements.txt .300RUN pip install --no-cache-dir --prefix=/install -r requirements.txt301302# Runtime stage303FROM python:3.12-slim304WORKDIR /app305RUN groupadd -r appgroup && useradd -r -g appgroup appuser306COPY --from=builder /install /usr/local307COPY . .308USER appuser309EXPOSE 8000310CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]311```312313---314315## Base Image Decision Tree316317```318Is it a compiled binary (Go, Rust, C)?319├── Yes → distroless/static or scratch320└── No321 ├── Need a shell for debugging?322 │ ├── Yes → alpine variant (e.g., node:20-alpine)323 │ └── No → distroless variant324 ├── Need glibc (not musl)?325 │ ├── Yes → slim variant (e.g., python:3.12-slim)326 │ └── No → alpine variant327 └── Need specific OS packages?328 ├── Many → debian-slim329 └── Few → alpine + apk add330```331332---333334## Proactive Triggers335336Flag these without being asked:337338- **Dockerfile uses :latest** → Suggest pinning to a specific version tag.339- **No .dockerignore** → Create one. At minimum: `.git`, `node_modules`, `__pycache__`, `.env`.340- **COPY . . before dependency install** → Cache bust. Reorder to install deps first.341- **Running as root** → Add USER instruction. No exceptions for production.342- **Secrets in ENV or ARG** → Use BuildKit secret mounts. Never bake secrets into layers.343- **Image over 1GB** → Multi-stage build required. No reason for a production image this large.344- **No healthcheck** → Add one. Orchestrators (Compose, K8s) need it for proper lifecycle management.345- **apt-get without cleanup in same layer** → `rm -rf /var/lib/apt/lists/*` in the same RUN.346347---348349## Installation350351### One-liner (any tool)352353```bash354git clone https://github.com/alirezarezvani/claude-skills.git355cp -r claude-skills/engineering/docker-development ~/.claude/skills/356```357358### Multi-tool install359360```bash361./scripts/convert.sh --skill docker-development --tool codex|gemini|cursor|windsurf|openclaw362```363364### OpenClaw365366```bash367clawhub install cs-docker-development368```369370---371372## Related Skills373374- **senior-devops** — Broader DevOps scope (CI/CD, IaC, monitoring). Complementary — use docker-development for container-specific work, senior-devops for pipeline and infrastructure.375- **senior-security** — Application security. Complementary — docker-development covers container security, senior-security covers application-level threats.376- **autoresearch-agent** — Can optimize Docker build times or image sizes as measurable experiments.377- **ci-cd-pipeline-builder** — Pipeline construction. Complementary — docker-development builds the containers, ci-cd-pipeline-builder deploys them.