Internal Safety Override
- Status: disabled by default.
- Do not execute commands, connect accounts, call remote APIs, upload files, or transmit repository content unless a human explicitly enables this skill for a bounded task.
- Never read
.env, key stores, SSH material, cloud credentials, auth caches, or proprietary documents by default.
- Audit categories: command, network, secrets.
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/ai-ops-skills.git
cp -r ai-ops-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## Internal Safety Override89- Status: disabled by default.10- Do not execute commands, connect accounts, call remote APIs, upload files, or transmit repository content unless a human explicitly enables this skill for a bounded task.11- Never read `.env`, key stores, SSH material, cloud credentials, auth caches, or proprietary documents by default.12- Audit categories: command, network, secrets.1314# Docker Development1516> Smaller images. Faster builds. Secure containers. No guesswork.1718Opinionated Docker workflow that turns bloated Dockerfiles into production-grade containers. Covers optimization, multi-stage builds, compose orchestration, and security hardening.1920Not a Docker tutorial — a set of concrete decisions about how to build containers that don't waste time, space, or attack surface.2122---2324## Slash Commands2526| Command | What it does |27|---------|-------------|28| `/docker:optimize` | Analyze and optimize a Dockerfile for size, speed, and layer caching |29| `/docker:compose` | Generate or improve docker-compose.yml with best practices |30| `/docker:security` | Audit a Dockerfile or running container for security issues |3132---3334## When This Skill Activates3536Recognize these patterns from the user:3738- "Optimize this Dockerfile"39- "My Docker build is slow"40- "Create a docker-compose for this project"41- "Is this Dockerfile secure?"42- "Reduce my Docker image size"43- "Set up multi-stage builds"44- "Docker best practices for [language/framework]"45- Any request involving: Dockerfile, docker-compose, container, image size, build cache, Docker security4647If the user has a Dockerfile or wants to containerize something → this skill applies.4849---5051## Workflow5253### `/docker:optimize` — Dockerfile Optimization54551. **Analyze current state**56 - Read the Dockerfile57 - Identify base image and its size58 - Count layers (each RUN/COPY/ADD = 1 layer)59 - Check for common anti-patterns60612. **Apply optimization checklist**6263 ```64 BASE IMAGE65 ├── Use specific tags, never :latest in production66 ├── Prefer slim/alpine variants (debian-slim > ubuntu > debian)67 ├── Pin digest for reproducibility in CI: image@sha256:...68 └── Match base to runtime needs (don't use python:3.12 for a compiled binary)6970 LAYER OPTIMIZATION71 ├── Combine related RUN commands with && \72 ├── Order layers: least-changing first (deps before source code)73 ├── Clean package manager cache in the same RUN layer74 ├── Use .dockerignore to exclude unnecessary files75 └── Separate build deps from runtime deps7677 BUILD CACHE78 ├── COPY dependency files before source code (package.json, requirements.txt, go.mod)79 ├── Install deps in a separate layer from code copy80 ├── Use BuildKit cache mounts: --mount=type=cache,target=/root/.cache81 └── Avoid COPY . . before dependency installation8283 MULTI-STAGE BUILDS84 ├── Stage 1: build (full SDK, build tools, dev deps)85 ├── Stage 2: runtime (minimal base, only production artifacts)86 ├── COPY --from=builder only what's needed87 └── Final image should have NO build tools, NO source code, NO dev deps88 ```89903. **Generate optimized Dockerfile**91 - Apply all relevant optimizations92 - Add inline comments explaining each decision93 - Report estimated size reduction94954. **Validate**96 ```bash97 python3 scripts/dockerfile_analyzer.py Dockerfile98 ```99100### `/docker:compose` — Docker Compose Configuration1011021. **Identify services**103 - Application (web, API, worker)104 - Database (postgres, mysql, redis, mongo)105 - Cache (redis, memcached)106 - Queue (rabbitmq, kafka)107 - Reverse proxy (nginx, traefik, caddy)1081092. **Apply compose best practices**110111 ```112 SERVICES113 ├── Use depends_on with condition: service_healthy114 ├── Add healthchecks for every service115 ├── Set resource limits (mem_limit, cpus)116 ├── Use named volumes for persistent data117 └── Pin image versions118119 NETWORKING120 ├── Create explicit networks (don't rely on default)121 ├── Separate frontend and backend networks122 ├── Only expose ports that need external access123 └── Use internal: true for backend-only networks124125 ENVIRONMENT126 ├── Use env_file for secrets, not inline environment127 ├── Never commit .env files (add to .gitignore)128 ├── Use variable substitution: ${VAR:-default}129 └── Document all required env vars130131 DEVELOPMENT vs PRODUCTION132 ├── Use compose profiles or override files133 ├── Dev: bind mounts for hot reload, debug ports exposed134 ├── Prod: named volumes, no debug ports, restart: unless-stopped135 └── docker-compose.override.yml for dev-only config136 ```1371383. **Generate compose file**139 - Output docker-compose.yml with healthchecks, networks, volumes140 - Generate .env.example with all required variables documented141 - Add dev/prod profile annotations142143### `/docker:security` — Container Security Audit1441451. **Dockerfile audit**146147 | Check | Severity | Fix |148 |-------|----------|-----|149 | Running as root | Critical | Add `USER nonroot` after creating user |150 | Using :latest tag | High | Pin to specific version |151 | Secrets in ENV/ARG | Critical | Use BuildKit secrets: `--mount=type=secret` |152 | COPY with broad glob | Medium | Use specific paths, add .dockerignore |153 | Unnecessary EXPOSE | Low | Only expose ports the app uses |154 | No HEALTHCHECK | Medium | Add HEALTHCHECK with appropriate interval |155 | Privileged instructions | High | Avoid `--privileged`, drop capabilities |156 | Package manager cache retained | Low | Clean in same RUN layer |1571582. **Runtime security checks**159160 | Check | Severity | Fix |161 |-------|----------|-----|162 | Container running as root | Critical | Set user in Dockerfile or compose |163 | Writable root filesystem | Medium | Use `read_only: true` in compose |164 | All capabilities retained | High | Drop all, add only needed: `cap_drop: [ALL]` |165 | No resource limits | Medium | Set `mem_limit` and `cpus` |166 | Host network mode | High | Use bridge or custom network |167 | Sensitive mounts | Critical | Never mount /etc, /var/run/docker.sock in prod |168 | No log driver configured | Low | Set `logging:` with size limits |1691703. **Generate security report**171 ```172 SECURITY AUDIT — [Dockerfile/Image name]173 Date: [timestamp]174175 CRITICAL: [count]176 HIGH: [count]177 MEDIUM: [count]178 LOW: [count]179180 [Detailed findings with fix recommendations]181 ```182183---184185## Tooling186187### `scripts/dockerfile_analyzer.py`188189CLI utility for static analysis of Dockerfiles.190191**Features:**192- Layer count and optimization suggestions193- Base image analysis with size estimates194- Anti-pattern detection (15+ rules)195- Security issue flagging196- Multi-stage build detection and validation197- JSON and text output198199**Usage:**200```bash201# Analyze a Dockerfile202python3 scripts/dockerfile_analyzer.py Dockerfile203204# JSON output205python3 scripts/dockerfile_analyzer.py Dockerfile --output json206207# Analyze with security focus208python3 scripts/dockerfile_analyzer.py Dockerfile --security209210# Check a specific directory211python3 scripts/dockerfile_analyzer.py path/to/Dockerfile212```213214### `scripts/compose_validator.py`215216CLI utility for validating docker-compose files.217218**Features:**219- Service dependency validation220- Healthcheck presence detection221- Network configuration analysis222- Volume mount validation223- Environment variable audit224- Port conflict detection225- Best practice scoring226227**Usage:**228```bash229# Validate a compose file230python3 scripts/compose_validator.py docker-compose.yml231232# JSON output233python3 scripts/compose_validator.py docker-compose.yml --output json234235# Strict mode (fail on warnings)236python3 scripts/compose_validator.py docker-compose.yml --strict237```238239---240241## Multi-Stage Build Patterns242243### Pattern 1: Compiled Language (Go, Rust, C++)244245```dockerfile246# Build stage247FROM golang:1.22-alpine AS builder248WORKDIR /app249COPY go.mod go.sum ./250RUN go mod download251COPY . .252RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app/server ./cmd/server253254# Runtime stage255FROM gcr.io/distroless/static-debian12256COPY --from=builder /app/server /server257USER nonroot:nonroot258ENTRYPOINT ["/server"]259```260261### Pattern 2: Node.js / TypeScript262263```dockerfile264# Dependencies stage265FROM node:20-alpine AS deps266WORKDIR /app267COPY package.json package-lock.json ./268RUN npm ci --production=false269270# Build stage271FROM deps AS builder272COPY . .273RUN npm run build274275# Runtime stage276FROM node:20-alpine277WORKDIR /app278RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001279COPY --from=builder /app/dist ./dist280COPY --from=deps /app/node_modules ./node_modules281COPY package.json ./282USER appuser283EXPOSE 3000284CMD ["node", "dist/index.js"]285```286287### Pattern 3: Python288289```dockerfile290# Build stage291FROM python:3.12-slim AS builder292WORKDIR /app293COPY requirements.txt .294RUN pip install --no-cache-dir --prefix=/install -r requirements.txt295296# Runtime stage297FROM python:3.12-slim298WORKDIR /app299RUN groupadd -r appgroup && useradd -r -g appgroup appuser300COPY --from=builder /install /usr/local301COPY . .302USER appuser303EXPOSE 8000304CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]305```306307---308309## Base Image Decision Tree310311```312Is it a compiled binary (Go, Rust, C)?313├── Yes → distroless/static or scratch314└── No315 ├── Need a shell for debugging?316 │ ├── Yes → alpine variant (e.g., node:20-alpine)317 │ └── No → distroless variant318 ├── Need glibc (not musl)?319 │ ├── Yes → slim variant (e.g., python:3.12-slim)320 │ └── No → alpine variant321 └── Need specific OS packages?322 ├── Many → debian-slim323 └── Few → alpine + apk add324```325326---327328## Proactive Triggers329330Flag these without being asked:331332- **Dockerfile uses :latest** → Suggest pinning to a specific version tag.333- **No .dockerignore** → Create one. At minimum: `.git`, `node_modules`, `__pycache__`, `.env`.334- **COPY . . before dependency install** → Cache bust. Reorder to install deps first.335- **Running as root** → Add USER instruction. No exceptions for production.336- **Secrets in ENV or ARG** → Use BuildKit secret mounts. Never bake secrets into layers.337- **Image over 1GB** → Multi-stage build required. No reason for a production image this large.338- **No healthcheck** → Add one. Orchestrators (Compose, K8s) need it for proper lifecycle management.339- **apt-get without cleanup in same layer** → `rm -rf /var/lib/apt/lists/*` in the same RUN.340341---342343## Installation344345### One-liner (any tool)346```bash347git clone https://github.com/alirezarezvani/ai-ops-skills.git348cp -r ai-ops-skills/engineering/docker-development ~/.claude/skills/349```350351### Multi-tool install352```bash353./scripts/convert.sh --skill docker-development --tool codex|gemini|cursor|windsurf|openclaw354```355356### OpenClaw357```bash358clawhub install cs-docker-development359```360361---362363## Related Skills364365- **senior-devops** — Broader DevOps scope (CI/CD, IaC, monitoring). Complementary — use docker-development for container-specific work, senior-devops for pipeline and infrastructure.366- **senior-security** — Application security. Complementary — docker-development covers container security, senior-security covers application-level threats.367- **autoresearch-agent** — Can optimize Docker build times or image sizes as measurable experiments.368- **ci-cd-pipeline-builder** — Pipeline construction. Complementary — docker-development builds the containers, ci-cd-pipeline-builder deploys them.