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
/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
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
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: MIT5---67# Docker Development89> Smaller images. Faster builds. Secure containers. No guesswork.1011Opinionated Docker workflow that turns bloated Dockerfiles into production-grade containers. Covers optimization, multi-stage builds, compose orchestration, and security hardening.1213Not a Docker tutorial — a set of concrete decisions about how to build containers that don't waste time, space, or attack surface.1415---1617## Slash Commands1819| Command | What it does |20|---------|-------------|21| `/docker:optimize` | Analyze and optimize a Dockerfile for size, speed, and layer caching |22| `/docker:compose` | Generate or improve docker-compose.yml with best practices |23| `/docker:security` | Audit a Dockerfile or running container for security issues |2425---2627## When This Skill Activates2829Recognize these patterns from the user:3031- "Optimize this Dockerfile"32- "My Docker build is slow"33- "Create a docker-compose for this project"34- "Is this Dockerfile secure?"35- "Reduce my Docker image size"36- "Set up multi-stage builds"37- "Docker best practices for [language/framework]"38- Any request involving: Dockerfile, docker-compose, container, image size, build cache, Docker security3940If the user has a Dockerfile or wants to containerize something → this skill applies.4142---4344## Workflow4546### `/docker:optimize` — Dockerfile Optimization47481. **Analyze current state**49 - Read the Dockerfile50 - Identify base image and its size51 - Count layers (each RUN/COPY/ADD = 1 layer)52 - Check for common anti-patterns53542. **Apply optimization checklist**5556 ```57 BASE IMAGE58 ├── Use specific tags, never :latest in production59 ├── Prefer slim/alpine variants (debian-slim > ubuntu > debian)60 ├── Pin digest for reproducibility in CI: image@sha256:...61 └── Match base to runtime needs (don't use python:3.12 for a compiled binary)6263 LAYER OPTIMIZATION64 ├── Combine related RUN commands with && \65 ├── Order layers: least-changing first (deps before source code)66 ├── Clean package manager cache in the same RUN layer67 ├── Use .dockerignore to exclude unnecessary files68 └── Separate build deps from runtime deps6970 BUILD CACHE71 ├── COPY dependency files before source code (package.json, requirements.txt, go.mod)72 ├── Install deps in a separate layer from code copy73 ├── Use BuildKit cache mounts: --mount=type=cache,target=/root/.cache74 └── Avoid COPY . . before dependency installation7576 MULTI-STAGE BUILDS77 ├── Stage 1: build (full SDK, build tools, dev deps)78 ├── Stage 2: runtime (minimal base, only production artifacts)79 ├── COPY --from=builder only what's needed80 └── Final image should have NO build tools, NO source code, NO dev deps81 ```82833. **Generate optimized Dockerfile**84 - Apply all relevant optimizations85 - Add inline comments explaining each decision86 - Report estimated size reduction87884. **Validate**89 ```bash90 python3 scripts/dockerfile_analyzer.py Dockerfile91 ```9293### `/docker:compose` — Docker Compose Configuration94951. **Identify services**96 - Application (web, API, worker)97 - Database (postgres, mysql, redis, mongo)98 - Cache (redis, memcached)99 - Queue (rabbitmq, kafka)100 - Reverse proxy (nginx, traefik, caddy)1011022. **Apply compose best practices**103104 ```105 SERVICES106 ├── Use depends_on with condition: service_healthy107 ├── Add healthchecks for every service108 ├── Set resource limits (mem_limit, cpus)109 ├── Use named volumes for persistent data110 └── Pin image versions111112 NETWORKING113 ├── Create explicit networks (don't rely on default)114 ├── Separate frontend and backend networks115 ├── Only expose ports that need external access116 └── Use internal: true for backend-only networks117118 ENVIRONMENT119 ├── Use env_file for secrets, not inline environment120 ├── Never commit .env files (add to .gitignore)121 ├── Use variable substitution: ${VAR:-default}122 └── Document all required env vars123124 DEVELOPMENT vs PRODUCTION125 ├── Use compose profiles or override files126 ├── Dev: bind mounts for hot reload, debug ports exposed127 ├── Prod: named volumes, no debug ports, restart: unless-stopped128 └── docker-compose.override.yml for dev-only config129 ```1301313. **Generate compose file**132 - Output docker-compose.yml with healthchecks, networks, volumes133 - Generate .env.example with all required variables documented134 - Add dev/prod profile annotations135136### `/docker:security` — Container Security Audit1371381. **Dockerfile audit**139140 | Check | Severity | Fix |141 |-------|----------|-----|142 | Running as root | Critical | Add `USER nonroot` after creating user |143 | Using :latest tag | High | Pin to specific version |144 | Secrets in ENV/ARG | Critical | Use BuildKit secrets: `--mount=type=secret` |145 | COPY with broad glob | Medium | Use specific paths, add .dockerignore |146 | Unnecessary EXPOSE | Low | Only expose ports the app uses |147 | No HEALTHCHECK | Medium | Add HEALTHCHECK with appropriate interval |148 | Privileged instructions | High | Avoid `--privileged`, drop capabilities |149 | Package manager cache retained | Low | Clean in same RUN layer |1501512. **Runtime security checks**152153 | Check | Severity | Fix |154 |-------|----------|-----|155 | Container running as root | Critical | Set user in Dockerfile or compose |156 | Writable root filesystem | Medium | Use `read_only: true` in compose |157 | All capabilities retained | High | Drop all, add only needed: `cap_drop: [ALL]` |158 | No resource limits | Medium | Set `mem_limit` and `cpus` |159 | Host network mode | High | Use bridge or custom network |160 | Sensitive mounts | Critical | Never mount /etc, /var/run/docker.sock in prod |161 | No log driver configured | Low | Set `logging:` with size limits |1621633. **Generate security report**164 ```165 SECURITY AUDIT — [Dockerfile/Image name]166 Date: [timestamp]167168 CRITICAL: [count]169 HIGH: [count]170 MEDIUM: [count]171 LOW: [count]172173 [Detailed findings with fix recommendations]174 ```175176---177178## Tooling179180### `scripts/dockerfile_analyzer.py`181182CLI utility for static analysis of Dockerfiles.183184**Features:**185- Layer count and optimization suggestions186- Base image analysis with size estimates187- Anti-pattern detection (15+ rules)188- Security issue flagging189- Multi-stage build detection and validation190- JSON and text output191192**Usage:**193```bash194# Analyze a Dockerfile195python3 scripts/dockerfile_analyzer.py Dockerfile196197# JSON output198python3 scripts/dockerfile_analyzer.py Dockerfile --output json199200# Analyze with security focus201python3 scripts/dockerfile_analyzer.py Dockerfile --security202203# Check a specific directory204python3 scripts/dockerfile_analyzer.py path/to/Dockerfile205```206207### `scripts/compose_validator.py`208209CLI utility for validating docker-compose files.210211**Features:**212- Service dependency validation213- Healthcheck presence detection214- Network configuration analysis215- Volume mount validation216- Environment variable audit217- Port conflict detection218- Best practice scoring219220**Usage:**221```bash222# Validate a compose file223python3 scripts/compose_validator.py docker-compose.yml224225# JSON output226python3 scripts/compose_validator.py docker-compose.yml --output json227228# Strict mode (fail on warnings)229python3 scripts/compose_validator.py docker-compose.yml --strict230```231232---233234## Multi-Stage Build Patterns235236### Pattern 1: Compiled Language (Go, Rust, C++)237238```dockerfile239# Build stage240FROM golang:1.22-alpine AS builder241WORKDIR /app242COPY go.mod go.sum ./243RUN go mod download244COPY . .245RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app/server ./cmd/server246247# Runtime stage248FROM gcr.io/distroless/static-debian12249COPY --from=builder /app/server /server250USER nonroot:nonroot251ENTRYPOINT ["/server"]252```253254### Pattern 2: Node.js / TypeScript255256```dockerfile257# Dependencies stage258FROM node:20-alpine AS deps259WORKDIR /app260COPY package.json package-lock.json ./261RUN npm ci --production=false262263# Build stage264FROM deps AS builder265COPY . .266RUN npm run build267268# Runtime stage269FROM node:20-alpine270WORKDIR /app271RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001272COPY --from=builder /app/dist ./dist273COPY --from=deps /app/node_modules ./node_modules274COPY package.json ./275USER appuser276EXPOSE 3000277CMD ["node", "dist/index.js"]278```279280### Pattern 3: Python281282```dockerfile283# Build stage284FROM python:3.12-slim AS builder285WORKDIR /app286COPY requirements.txt .287RUN pip install --no-cache-dir --prefix=/install -r requirements.txt288289# Runtime stage290FROM python:3.12-slim291WORKDIR /app292RUN groupadd -r appgroup && useradd -r -g appgroup appuser293COPY --from=builder /install /usr/local294COPY . .295USER appuser296EXPOSE 8000297CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]298```299300---301302## Base Image Decision Tree303304```305Is it a compiled binary (Go, Rust, C)?306├── Yes → distroless/static or scratch307└── No308 ├── Need a shell for debugging?309 │ ├── Yes → alpine variant (e.g., node:20-alpine)310 │ └── No → distroless variant311 ├── Need glibc (not musl)?312 │ ├── Yes → slim variant (e.g., python:3.12-slim)313 │ └── No → alpine variant314 └── Need specific OS packages?315 ├── Many → debian-slim316 └── Few → alpine + apk add317```318319---320321## Proactive Triggers322323Flag these without being asked:324325- **Dockerfile uses :latest** → Suggest pinning to a specific version tag.326- **No .dockerignore** → Create one. At minimum: `.git`, `node_modules`, `__pycache__`, `.env`.327- **COPY . . before dependency install** → Cache bust. Reorder to install deps first.328- **Running as root** → Add USER instruction. No exceptions for production.329- **Secrets in ENV or ARG** → Use BuildKit secret mounts. Never bake secrets into layers.330- **Image over 1GB** → Multi-stage build required. No reason for a production image this large.331- **No healthcheck** → Add one. Orchestrators (Compose, K8s) need it for proper lifecycle management.332- **apt-get without cleanup in same layer** → `rm -rf /var/lib/apt/lists/*` in the same RUN.333334---335336## Installation337338### One-liner (any tool)339```bash340git clone https://github.com/alirezarezvani/claude-skills.git341cp -r claude-skills/engineering/docker-development ~/.claude/skills/342```343344### Multi-tool install345```bash346./scripts/convert.sh --skill docker-development --tool codex|gemini|cursor|windsurf|openclaw347```348349### OpenClaw350```bash351clawhub install cs-docker-development352```353354---355356## Related Skills357358- **senior-devops** — Broader DevOps scope (CI/CD, IaC, monitoring). Complementary — use docker-development for container-specific work, senior-devops for pipeline and infrastructure.359- **senior-security** — Application security. Complementary — docker-development covers container security, senior-security covers application-level threats.360- **autoresearch-agent** — Can optimize Docker build times or image sizes as measurable experiments.361- **ci-cd-pipeline-builder** — Pipeline construction. Complementary — docker-development builds the containers, ci-cd-pipeline-builder deploys them.362