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