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-development
3description: "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-compos..."
4version: 1.0.0
5author:
6 name: "Alireza Rezvani"
7 github: alirezarezvani
8tags: [docker, development]
9category: engineering
10platforms: [macos, linux, windows]
11license: MIT
12metadata:
13 hermes:
14 related_skills: [docker, development]
15 source: https://skillmd.com/skills/nous-hermeshub/docker-development
16 upstream: "claude-skills"
17 original_author: "Alireza Rezvani"
18 original_category: "engineering"
19---
20
21# Docker Development
22
23> Smaller images. Faster builds. Secure containers. No guesswork.
24
25Opinionated Docker workflow that turns bloated Dockerfiles into production-grade containers. Covers optimization, multi-stage builds, compose orchestration, and security hardening.
26
27Not a Docker tutorial — a set of concrete decisions about how to build containers that don't waste time, space, or attack surface.
28
29---
30
31## Slash Commands
32
33| Command | What it does |
34|---------|-------------|
35| `/docker:optimize` | Analyze and optimize a Dockerfile for size, speed, and layer caching |
36| `/docker:compose` | Generate or improve docker-compose.yml with best practices |
37| `/docker:security` | Audit a Dockerfile or running container for security issues |
38
39---
40
41## When This Skill Activates
42
43Recognize these patterns from the user:
44
45- "Optimize this Dockerfile"
46- "My Docker build is slow"
47- "Create a docker-compose for this project"
48- "Is this Dockerfile secure?"
49- "Reduce my Docker image size"
50- "Set up multi-stage builds"
51- "Docker best practices for [language/framework]"
52- Any request involving: Dockerfile, docker-compose, container, image size, build cache, Docker security
53
54If the user has a Dockerfile or wants to containerize something → this skill applies.
55
56---
57
58## Workflow
59
60### `/docker:optimize` — Dockerfile Optimization
61
621. **Analyze current state**
63 - Read the Dockerfile
64 - Identify base image and its size
65 - Count layers (each RUN/COPY/ADD = 1 layer)
66 - Check for common anti-patterns
67
682. **Apply optimization checklist**
69
70 ```
71 BASE IMAGE
72 ├── Use specific tags, never :latest in production
73 ├── Prefer slim/alpine variants (debian-slim > ubuntu > debian)
74 ├── Pin digest for reproducibility in CI: image@sha256:...
75 └── Match base to runtime needs (don't use python:3.12 for a compiled binary)
76
77 LAYER OPTIMIZATION
78 ├── Combine related RUN commands with && \
79 ├── Order layers: least-changing first (deps before source code)
80 ├── Clean package manager cache in the same RUN layer
81 ├── Use .dockerignore to exclude unnecessary files
82 └── Separate build deps from runtime deps
83
84 BUILD CACHE
85 ├── COPY dependency files before source code (package.json, requirements.txt, go.mod)
86 ├── Install deps in a separate layer from code copy
87 ├── Use BuildKit cache mounts: --mount=type=cache,target=/root/.cache
88 └── Avoid COPY . . before dependency installation
89
90 MULTI-STAGE BUILDS
91 ├── Stage 1: build (full SDK, build tools, dev deps)
92 ├── Stage 2: runtime (minimal base, only production artifacts)
93 ├── COPY --from=builder only what's needed
94 └── Final image should have NO build tools, NO source code, NO dev deps
95 ```
96
973. **Generate optimized Dockerfile**
98 - Apply all relevant optimizations
99 - Add inline comments explaining each decision
100 - Report estimated size reduction
101
1024. **Validate**
103 ```bash
104 python3 scripts/dockerfile_analyzer.py Dockerfile
105 ```
106
107### `/docker:compose` — Docker Compose Configuration
108
1091. **Identify services**
110 - Application (web, API, worker)
111 - Database (postgres, mysql, redis, mongo)
112 - Cache (redis, memcached)
113 - Queue (rabbitmq, kafka)
114 - Reverse proxy (nginx, traefik, caddy)
115
1162. **Apply compose best practices**
117
118 ```
119 SERVICES
120 ├── Use depends_on with condition: service_healthy
121 ├── Add healthchecks for every service
122 ├── Set resource limits (mem_limit, cpus)
123 ├── Use named volumes for persistent data
124 └── Pin image versions
125
126 NETWORKING
127 ├── Create explicit networks (don't rely on default)
128 ├── Separate frontend and backend networks
129 ├── Only expose ports that need external access
130 └── Use internal: true for backend-only networks
131
132 ENVIRONMENT
133 ├── Use env_file for secrets, not inline environment
134 ├── Never commit .env files (add to .gitignore)
135 ├── Use variable substitution: ${VAR:-default}
136 └── Document all required env vars
137
138 DEVELOPMENT vs PRODUCTION
139 ├── Use compose profiles or override files
140 ├── Dev: bind mounts for hot reload, debug ports exposed
141 ├── Prod: named volumes, no debug ports, restart: unless-stopped
142 └── docker-compose.override.yml for dev-only config
143 ```
144
1453. **Generate compose file**
146 - Output docker-compose.yml with healthchecks, networks, volumes
147 - Generate .env.example with all required variables documented
148 - Add dev/prod profile annotations
149
150### `/docker:security` — Container Security Audit
151
1521. **Dockerfile audit**
153
154 | Check | Severity | Fix |
155 |-------|----------|-----|
156 | Running as root | Critical | Add `USER nonroot` after creating user |
157 | Using :latest tag | High | Pin to specific version |
158 | Secrets in ENV/ARG | Critical | Use BuildKit secrets: `--mount=type=secret` |
159 | COPY with broad glob | Medium | Use specific paths, add .dockerignore |
160 | Unnecessary EXPOSE | Low | Only expose ports the app uses |
161 | No HEALTHCHECK | Medium | Add HEALTHCHECK with appropriate interval |
162 | Privileged instructions | High | Avoid `--privileged`, drop capabilities |
163 | Package manager cache retained | Low | Clean in same RUN layer |
164
1652. **Runtime security checks**
166
167 | Check | Severity | Fix |
168 |-------|----------|-----|
169 | Container running as root | Critical | Set user in Dockerfile or compose |
170 | Writable root filesystem | Medium | Use `read_only: true` in compose |
171 | All capabilities retained | High | Drop all, add only needed: `cap_drop: [ALL]` |
172 | No resource limits | Medium | Set `mem_limit` and `cpus` |
173 | Host network mode | High | Use bridge or custom network |
174 | Sensitive mounts | Critical | Never mount /etc, /var/run/docker.sock in prod |
175 | No log driver configured | Low | Set `logging:` with size limits |
176
1773. **Generate security report**
178 ```
179 SECURITY AUDIT — [Dockerfile/Image name]
180 Date: [timestamp]
181
182 CRITICAL: [count]
183 HIGH: [count]
184 MEDIUM: [count]
185 LOW: [count]
186
187 [Detailed findings with fix recommendations]
188 ```
189
190---
191
192## Tooling
193
194### `scripts/dockerfile_analyzer.py`
195
196CLI utility for static analysis of Dockerfiles.
197
198**Features:**
199- Layer count and optimization suggestions
200- Base image analysis with size estimates
201- Anti-pattern detection (15+ rules)
202- Security issue flagging
203- Multi-stage build detection and validation
204- JSON and text output
205
206**Usage:**
207```bash
208# Analyze a Dockerfile
209python3 scripts/dockerfile_analyzer.py Dockerfile
210
211# JSON output
212python3 scripts/dockerfile_analyzer.py Dockerfile --output json
213
214# Analyze with security focus
215python3 scripts/dockerfile_analyzer.py Dockerfile --security
216
217# Check a specific directory
218python3 scripts/dockerfile_analyzer.py path/to/Dockerfile
219```
220
221### `scripts/compose_validator.py`
222
223CLI utility for validating docker-compose files.
224
225**Features:**
226- Service dependency validation
227- Healthcheck presence detection
228- Network configuration analysis
229- Volume mount validation
230- Environment variable audit
231- Port conflict detection
232- Best practice scoring
233
234**Usage:**
235```bash
236# Validate a compose file
237python3 scripts/compose_validator.py docker-compose.yml
238
239# JSON output
240python3 scripts/compose_validator.py docker-compose.yml --output json
241
242# Strict mode (fail on warnings)
243python3 scripts/compose_validator.py docker-compose.yml --strict
244```
245
246---
247
248## Multi-Stage Build Patterns
249
250### Pattern 1: Compiled Language (Go, Rust, C++)
251
252```dockerfile
253# Build stage
254FROM golang:1.22-alpine AS builder
255WORKDIR /app
256COPY go.mod go.sum ./
257RUN go mod download
258COPY . .
259RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app/server ./cmd/server
260
261# Runtime stage
262FROM gcr.io/distroless/static-debian12
263COPY --from=builder /app/server /server
264USER nonroot:nonroot
265ENTRYPOINT ["/server"]
266```
267
268### Pattern 2: Node.js / TypeScript
269
270```dockerfile
271# Dependencies stage
272FROM node:20-alpine AS deps
273WORKDIR /app
274COPY package.json package-lock.json ./
275RUN npm ci --production=false
276
277# Build stage
278FROM deps AS builder
279COPY . .
280RUN npm run build
281
282# Runtime stage
283FROM node:20-alpine
284WORKDIR /app
285RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001
286COPY --from=builder /app/dist ./dist
287COPY --from=deps /app/node_modules ./node_modules
288COPY package.json ./
289USER appuser
290EXPOSE 3000
291CMD ["node", "dist/index.js"]
292```
293
294### Pattern 3: Python
295
296```dockerfile
297# Build stage
298FROM python:3.12-slim AS builder
299WORKDIR /app
300COPY requirements.txt .
301RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
302
303# Runtime stage
304FROM python:3.12-slim
305WORKDIR /app
306RUN groupadd -r appgroup && useradd -r -g appgroup appuser
307COPY --from=builder /install /usr/local
308COPY . .
309USER appuser
310EXPOSE 8000
311CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
312```
313
314---
315
316## Base Image Decision Tree
317
318```
319Is it a compiled binary (Go, Rust, C)?
320├── Yes → distroless/static or scratch
321└── No
322 ├── Need a shell for debugging?
323 │ ├── Yes → alpine variant (e.g., node:20-alpine)
324 │ └── No → distroless variant
325 ├── Need glibc (not musl)?
326 │ ├── Yes → slim variant (e.g., python:3.12-slim)
327 │ └── No → alpine variant
328 └── Need specific OS packages?
329 ├── Many → debian-slim
330 └── Few → alpine + apk add
331```
332
333---
334
335## Proactive Triggers
336
337Flag these without being asked:
338
339- **Dockerfile uses :latest** → Suggest pinning to a specific version tag.
340- **No .dockerignore** → Create one. At minimum: `.git`, `node_modules`, `__pycache__`, `.env`.
341- **COPY . . before dependency install** → Cache bust. Reorder to install deps first.
342- **Running as root** → Add USER instruction. No exceptions for production.
343- **Secrets in ENV or ARG** → Use BuildKit secret mounts. Never bake secrets into layers.
344- **Image over 1GB** → Multi-stage build required. No reason for a production image this large.
345- **No healthcheck** → Add one. Orchestrators (Compose, K8s) need it for proper lifecycle management.
346- **apt-get without cleanup in same layer** → `rm -rf /var/lib/apt/lists/*` in the same RUN.
347
348---
349
350## Installation
351
352### One-liner (any tool)
353```bash
354git clone https://github.com/alirezarezvani/claude-skills.git
355cp -r claude-skills/engineering/docker-development ~/.claude/skills/
356```
357
358### Multi-tool install
359```bash
360./scripts/convert.sh --skill docker-development --tool codex|gemini|cursor|windsurf|openclaw
361```
362
363### OpenClaw
364```bash
365clawhub install cs-docker-development
366```
367
368---
369
370## Related Skills
371
372- **senior-devops** — Broader DevOps scope (CI/CD, IaC, monitoring). Complementary — use docker-development for container-specific work, senior-devops for pipeline and infrastructure.
373- **senior-security** — Application security. Complementary — docker-development covers container security, senior-security covers application-level threats.
374- **autoresearch-agent** — Can optimize Docker build times or image sizes as measurable experiments.
375- **ci-cd-pipeline-builder** — Pipeline construction. Complementary — docker-development builds the containers, ci-cd-pipeline-builder deploys them.