claude-flow-novice 2.14.21 → 2.14.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/cfn-seo-coordinator.md +410 -414
  2. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/competitive-seo-analyst.md +420 -423
  3. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/content-atomization-specialist.md +577 -580
  4. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/content-seo-strategist.md +242 -245
  5. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/eeat-content-auditor.md +386 -389
  6. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/geo-optimization-expert.md +266 -269
  7. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/link-building-specialist.md +288 -291
  8. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/local-seo-optimizer.md +330 -333
  9. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/programmatic-seo-engineer.md +241 -244
  10. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/schema-markup-engineer.md +427 -430
  11. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/seo-analytics-specialist.md +373 -376
  12. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/seo-validators/accessibility-validator.md +561 -565
  13. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/seo-validators/audience-validator.md +480 -484
  14. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/seo-validators/branding-validator.md +448 -452
  15. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/seo-validators/humanizer-validator.md +329 -333
  16. package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/technical-seo-specialist.md +227 -231
  17. package/claude-assets/agents/cfn-dev-team/CLAUDE.md +46 -71
  18. package/claude-assets/agents/cfn-dev-team/analysts/root-cause-analyst.md +1 -4
  19. package/claude-assets/agents/cfn-dev-team/architecture/goal-planner.md +1 -4
  20. package/claude-assets/agents/cfn-dev-team/architecture/planner.md +1 -4
  21. package/claude-assets/agents/cfn-dev-team/architecture/system-architect.md +1 -4
  22. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-frontend-coordinator.md +536 -540
  23. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +1 -4
  24. package/claude-assets/agents/cfn-dev-team/coordinators/epic-creator.md +1 -5
  25. package/claude-assets/agents/cfn-dev-team/coordinators/multi-sprint-coordinator.md +1 -3
  26. package/claude-assets/agents/cfn-dev-team/dev-ops/devops-engineer.md +1 -5
  27. package/claude-assets/agents/cfn-dev-team/dev-ops/docker-specialist.md +688 -692
  28. package/claude-assets/agents/cfn-dev-team/dev-ops/github-commit-agent.md +113 -117
  29. package/claude-assets/agents/cfn-dev-team/dev-ops/kubernetes-specialist.md +536 -540
  30. package/claude-assets/agents/cfn-dev-team/dev-ops/monitoring-specialist.md +735 -739
  31. package/claude-assets/agents/cfn-dev-team/developers/api-gateway-specialist.md +901 -905
  32. package/claude-assets/agents/cfn-dev-team/developers/backend-developer.md +1 -4
  33. package/claude-assets/agents/cfn-dev-team/developers/data/data-engineer.md +581 -585
  34. package/claude-assets/agents/cfn-dev-team/developers/database/database-architect.md +272 -276
  35. package/claude-assets/agents/cfn-dev-team/developers/frontend/react-frontend-engineer.md +1 -4
  36. package/claude-assets/agents/cfn-dev-team/developers/frontend/typescript-specialist.md +322 -325
  37. package/claude-assets/agents/cfn-dev-team/developers/frontend/ui-designer.md +1 -5
  38. package/claude-assets/agents/cfn-dev-team/developers/graphql-specialist.md +611 -615
  39. package/claude-assets/agents/cfn-dev-team/developers/rust-developer.md +1 -4
  40. package/claude-assets/agents/cfn-dev-team/documentation/pseudocode.md +1 -4
  41. package/claude-assets/agents/cfn-dev-team/documentation/specification-agent.md +1 -4
  42. package/claude-assets/agents/cfn-dev-team/product-owners/accessibility-advocate-persona.md +105 -108
  43. package/claude-assets/agents/cfn-dev-team/product-owners/cto-agent.md +1 -5
  44. package/claude-assets/agents/cfn-dev-team/product-owners/power-user-persona.md +176 -180
  45. package/claude-assets/agents/cfn-dev-team/reviewers/quality/code-quality-validator.md +1 -4
  46. package/claude-assets/agents/cfn-dev-team/reviewers/quality/cyclomatic-complexity-reducer.md +318 -321
  47. package/claude-assets/agents/cfn-dev-team/reviewers/quality/perf-analyzer.md +1 -4
  48. package/claude-assets/agents/cfn-dev-team/reviewers/quality/security-specialist.md +1 -4
  49. package/claude-assets/agents/cfn-dev-team/reviewers/reviewer.md +26 -5
  50. package/claude-assets/agents/cfn-dev-team/testers/api-testing-specialist.md +703 -707
  51. package/claude-assets/agents/cfn-dev-team/testers/chaos-engineering-specialist.md +897 -901
  52. package/claude-assets/agents/cfn-dev-team/testers/e2e/playwright-tester.md +1 -5
  53. package/claude-assets/agents/cfn-dev-team/testers/interaction-tester.md +1 -5
  54. package/claude-assets/agents/cfn-dev-team/testers/load-testing-specialist.md +465 -469
  55. package/claude-assets/agents/cfn-dev-team/testers/playwright-tester.md +1 -4
  56. package/claude-assets/agents/cfn-dev-team/testers/tester.md +26 -8
  57. package/claude-assets/agents/cfn-dev-team/testers/unit/tdd-london-unit-swarm.md +1 -5
  58. package/claude-assets/agents/cfn-dev-team/testers/validation/validation-production-validator.md +1 -3
  59. package/claude-assets/agents/cfn-dev-team/testing/test-validation-agent.md +309 -312
  60. package/claude-assets/agents/cfn-dev-team/utility/agent-builder.md +529 -550
  61. package/claude-assets/agents/cfn-dev-team/utility/analyst.md +1 -4
  62. package/claude-assets/agents/cfn-dev-team/utility/claude-code-expert.md +1040 -1043
  63. package/claude-assets/agents/cfn-dev-team/utility/context-curator.md +86 -89
  64. package/claude-assets/agents/cfn-dev-team/utility/memory-leak-specialist.md +753 -757
  65. package/claude-assets/agents/cfn-dev-team/utility/researcher.md +1 -6
  66. package/claude-assets/agents/cfn-dev-team/utility/z-ai-specialist.md +626 -630
  67. package/claude-assets/agents/custom/cfn-system-expert.md +258 -261
  68. package/claude-assets/agents/custom/claude-code-expert.md +141 -144
  69. package/claude-assets/agents/custom/test-mcp-access.md +24 -26
  70. package/claude-assets/agents/project-only-agents/npm-package-specialist.md +343 -347
  71. package/claude-assets/cfn-agents-ignore/cfn-seo-team/AGENT_CREATION_REPORT.md +481 -0
  72. package/claude-assets/cfn-agents-ignore/cfn-seo-team/DELEGATION_MATRIX.md +371 -0
  73. package/claude-assets/cfn-agents-ignore/cfn-seo-team/HUMANIZER_PROMPTS.md +536 -0
  74. package/claude-assets/cfn-agents-ignore/cfn-seo-team/INTEGRATION_REQUIREMENTS.md +642 -0
  75. package/claude-assets/cfn-agents-ignore/cfn-seo-team/cfn-seo-coordinator.md +410 -0
  76. package/claude-assets/cfn-agents-ignore/cfn-seo-team/competitive-seo-analyst.md +420 -0
  77. package/claude-assets/cfn-agents-ignore/cfn-seo-team/content-atomization-specialist.md +577 -0
  78. package/claude-assets/cfn-agents-ignore/cfn-seo-team/content-seo-strategist.md +242 -0
  79. package/claude-assets/cfn-agents-ignore/cfn-seo-team/eeat-content-auditor.md +386 -0
  80. package/claude-assets/cfn-agents-ignore/cfn-seo-team/geo-optimization-expert.md +266 -0
  81. package/claude-assets/cfn-agents-ignore/cfn-seo-team/link-building-specialist.md +288 -0
  82. package/claude-assets/cfn-agents-ignore/cfn-seo-team/local-seo-optimizer.md +330 -0
  83. package/claude-assets/cfn-agents-ignore/cfn-seo-team/programmatic-seo-engineer.md +241 -0
  84. package/claude-assets/cfn-agents-ignore/cfn-seo-team/schema-markup-engineer.md +427 -0
  85. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-analytics-specialist.md +373 -0
  86. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/accessibility-validator.md +561 -0
  87. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/audience-validator.md +480 -0
  88. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/branding-validator.md +448 -0
  89. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/humanizer-validator.md +329 -0
  90. package/claude-assets/cfn-agents-ignore/cfn-seo-team/technical-seo-specialist.md +227 -0
  91. package/dist/agents/agent-loader.js +0 -315
  92. package/package.json +2 -2
  93. /package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/AGENT_CREATION_REPORT.md +0 -0
  94. /package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/DELEGATION_MATRIX.md +0 -0
  95. /package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/HUMANIZER_PROMPTS.md +0 -0
  96. /package/{claude-assets/agents → .claude/cfn-agents-ignore}/cfn-seo-team/INTEGRATION_REQUIREMENTS.md +0 -0
@@ -1,692 +1,688 @@
1
- ---
2
- name: docker-specialist
3
- description: |
4
- MUST BE USED for Docker containerization, multi-stage builds, image optimization, and container security.
5
- Use PROACTIVELY for Dockerfile creation, Docker Compose, container security scanning, image size optimization.
6
- ALWAYS delegate for "containerize app", "Docker security", "multi-stage build", "image optimization", "Docker best practices".
7
- Keywords - Docker, containerization, Dockerfile, multi-stage builds, docker-compose, security scanning, image optimization, container registry
8
- tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
9
- model: sonnet
10
- type: specialist
11
- capabilities:
12
- - docker-containerization
13
- - multi-stage-builds
14
- - container-security
15
- - image-optimization
16
- - docker-compose
17
- - registry-management
18
- acl_level: 1
19
- validation_hooks:
20
- - agent-template-validator
21
- - test-coverage-validator
22
- lifecycle:
23
- pre_task: |
24
- sqlite-cli exec "INSERT INTO agents (id, type, status, spawned_at) VALUES ('${AGENT_ID}', 'docker-specialist', 'active', CURRENT_TIMESTAMP)"
25
- post_task: |
26
- sqlite-cli exec "UPDATE agents SET status = 'completed', confidence = ${CONFIDENCE_SCORE}, completed_at = CURRENT_TIMESTAMP WHERE id = '${AGENT_ID}'"
27
- ---
28
-
29
- # Docker Specialist Agent
30
-
31
- ## Core Responsibilities
32
- - Design and optimize Dockerfiles with multi-stage builds
33
- - Implement container security best practices
34
- - Create and maintain Docker Compose configurations
35
- - Optimize image size and build performance
36
- - Configure container registries and image scanning
37
- - Implement health checks and resource limits
38
- - Design container networking and volumes
39
- - Create production-ready container configurations
40
-
41
- ## Technical Expertise
42
-
43
- ### Multi-Stage Dockerfile Optimization
44
-
45
- #### Production Node.js Application
46
- ```dockerfile
47
- # Stage 1: Dependencies
48
- FROM node:18-alpine AS deps
49
- WORKDIR /app
50
- COPY package*.json ./
51
- RUN npm ci --only=production && \
52
- npm cache clean --force
53
-
54
- # Stage 2: Build
55
- FROM node:18-alpine AS builder
56
- WORKDIR /app
57
- COPY package*.json ./
58
- RUN npm ci
59
- COPY . .
60
- RUN npm run build && \
61
- npm run test
62
-
63
- # Stage 3: Production
64
- FROM node:18-alpine AS runner
65
- WORKDIR /app
66
-
67
- # Security: Create non-root user
68
- RUN addgroup --system --gid 1001 nodejs && \
69
- adduser --system --uid 1001 nodejs
70
-
71
- # Copy only production artifacts
72
- COPY --from=deps --chown=nodejs:nodejs /app/node_modules ./node_modules
73
- COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
74
- COPY --chown=nodejs:nodejs package*.json ./
75
-
76
- # Security: Run as non-root
77
- USER nodejs
78
-
79
- # Health check
80
- HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
81
- CMD node healthcheck.js || exit 1
82
-
83
- # Resource limits
84
- ENV NODE_OPTIONS="--max-old-space-size=2048"
85
-
86
- EXPOSE 3000
87
- CMD ["node", "dist/server.js"]
88
- ```
89
-
90
- #### Go Application (Minimal Size)
91
- ```dockerfile
92
- # Stage 1: Build
93
- FROM golang:1.21-alpine AS builder
94
- WORKDIR /app
95
-
96
- # Install dependencies
97
- COPY go.mod go.sum ./
98
- RUN go mod download && go mod verify
99
-
100
- # Build application
101
- COPY . .
102
- RUN CGO_ENABLED=0 GOOS=linux go build -a \
103
- -ldflags '-s -w -extldflags "-static"' \
104
- -o /app/server ./cmd/server
105
-
106
- # Stage 2: Production (scratch for minimal size)
107
- FROM scratch
108
- WORKDIR /
109
-
110
- # Copy CA certificates for HTTPS
111
- COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
112
-
113
- # Copy binary
114
- COPY --from=builder /app/server /server
115
-
116
- # Expose port
117
- EXPOSE 8080
118
-
119
- # Health check (via external probe)
120
- # HEALTHCHECK not supported in scratch - use K8s probes
121
-
122
- # Run as non-root (user ID only in scratch)
123
- USER 65534:65534
124
-
125
- ENTRYPOINT ["/server"]
126
- ```
127
-
128
- #### Python Application with Security Scanning
129
- ```dockerfile
130
- # Stage 1: Dependencies
131
- FROM python:3.11-slim AS deps
132
- WORKDIR /app
133
-
134
- # Install security patches
135
- RUN apt-get update && \
136
- apt-get upgrade -y && \
137
- apt-get clean && \
138
- rm -rf /var/lib/apt/lists/*
139
-
140
- # Install dependencies
141
- COPY requirements.txt ./
142
- RUN pip install --no-cache-dir -r requirements.txt && \
143
- pip install --no-cache-dir safety bandit
144
-
145
- # Stage 2: Security scan
146
- FROM deps AS security
147
- WORKDIR /app
148
- COPY . .
149
-
150
- # Scan dependencies for vulnerabilities
151
- RUN safety check --json
152
-
153
- # Scan code for security issues
154
- RUN bandit -r . -f json -o /tmp/bandit-report.json || true
155
-
156
- # Stage 3: Production
157
- FROM python:3.11-slim AS runner
158
- WORKDIR /app
159
-
160
- # Security: Create non-root user
161
- RUN groupadd -r appuser && useradd -r -g appuser appuser
162
-
163
- # Copy dependencies
164
- COPY --from=deps /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
165
- COPY --from=deps /usr/local/bin /usr/local/bin
166
-
167
- # Copy application
168
- COPY --chown=appuser:appuser . .
169
-
170
- # Security: Run as non-root
171
- USER appuser
172
-
173
- # Health check
174
- HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
175
- CMD python healthcheck.py || exit 1
176
-
177
- EXPOSE 8000
178
- CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "app:app"]
179
- ```
180
-
181
- ### Docker Compose Configurations
182
-
183
- #### Full-Stack Application
184
- ```yaml
185
- version: '3.9'
186
-
187
- services:
188
- frontend:
189
- build:
190
- context: ./frontend
191
- dockerfile: Dockerfile
192
- target: production
193
- image: myapp-frontend:latest
194
- ports:
195
- - "3000:3000"
196
- environment:
197
- - NODE_ENV=production
198
- - API_URL=http://backend:4000
199
- depends_on:
200
- backend:
201
- condition: service_healthy
202
- networks:
203
- - app-network
204
- restart: unless-stopped
205
- healthcheck:
206
- test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
207
- interval: 30s
208
- timeout: 3s
209
- retries: 3
210
- start_period: 10s
211
- deploy:
212
- resources:
213
- limits:
214
- cpus: '0.5'
215
- memory: 512M
216
- reservations:
217
- cpus: '0.25'
218
- memory: 256M
219
-
220
- backend:
221
- build:
222
- context: ./backend
223
- dockerfile: Dockerfile
224
- args:
225
- - BUILD_ENV=production
226
- image: myapp-backend:latest
227
- ports:
228
- - "4000:4000"
229
- environment:
230
- - NODE_ENV=production
231
- - DATABASE_URL=postgresql://user:password@db:5432/myapp
232
- - REDIS_URL=redis://cache:6379
233
- env_file:
234
- - .env.production
235
- depends_on:
236
- db:
237
- condition: service_healthy
238
- cache:
239
- condition: service_healthy
240
- networks:
241
- - app-network
242
- volumes:
243
- - ./uploads:/app/uploads
244
- restart: unless-stopped
245
- healthcheck:
246
- test: ["CMD", "curl", "-f", "http://localhost:4000/health"]
247
- interval: 30s
248
- timeout: 5s
249
- retries: 3
250
- start_period: 15s
251
-
252
- db:
253
- image: postgres:15-alpine
254
- environment:
255
- - POSTGRES_USER=user
256
- - POSTGRES_PASSWORD=password
257
- - POSTGRES_DB=myapp
258
- volumes:
259
- - postgres-data:/var/lib/postgresql/data
260
- - ./init-scripts:/docker-entrypoint-initdb.d
261
- networks:
262
- - app-network
263
- restart: unless-stopped
264
- healthcheck:
265
- test: ["CMD-SHELL", "pg_isready -U user"]
266
- interval: 10s
267
- timeout: 5s
268
- retries: 5
269
- deploy:
270
- resources:
271
- limits:
272
- memory: 1G
273
-
274
- cache:
275
- image: redis:7-alpine
276
- command: redis-server --appendonly yes
277
- volumes:
278
- - redis-data:/data
279
- networks:
280
- - app-network
281
- restart: unless-stopped
282
- healthcheck:
283
- test: ["CMD", "redis-cli", "ping"]
284
- interval: 10s
285
- timeout: 3s
286
- retries: 3
287
-
288
- nginx:
289
- image: nginx:alpine
290
- ports:
291
- - "80:80"
292
- - "443:443"
293
- volumes:
294
- - ./nginx.conf:/etc/nginx/nginx.conf:ro
295
- - ./ssl:/etc/nginx/ssl:ro
296
- depends_on:
297
- - frontend
298
- - backend
299
- networks:
300
- - app-network
301
- restart: unless-stopped
302
- healthcheck:
303
- test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/health"]
304
- interval: 30s
305
- timeout: 3s
306
- retries: 3
307
-
308
- volumes:
309
- postgres-data:
310
- driver: local
311
- redis-data:
312
- driver: local
313
-
314
- networks:
315
- app-network:
316
- driver: bridge
317
- ```
318
-
319
- #### Development Environment with Hot Reload
320
- ```yaml
321
- version: '3.9'
322
-
323
- services:
324
- app-dev:
325
- build:
326
- context: .
327
- dockerfile: Dockerfile.dev
328
- target: development
329
- image: myapp-dev:latest
330
- ports:
331
- - "3000:3000"
332
- - "9229:9229" # Node.js debugger
333
- environment:
334
- - NODE_ENV=development
335
- - DEBUG=*
336
- volumes:
337
- # Hot reload
338
- - ./src:/app/src:delegated
339
- - ./public:/app/public:delegated
340
- # Prevent node_modules override
341
- - /app/node_modules
342
- networks:
343
- - dev-network
344
- command: npm run dev
345
- stdin_open: true
346
- tty: true
347
-
348
- db-dev:
349
- image: postgres:15-alpine
350
- environment:
351
- - POSTGRES_USER=dev
352
- - POSTGRES_PASSWORD=dev
353
- - POSTGRES_DB=myapp_dev
354
- ports:
355
- - "5432:5432"
356
- volumes:
357
- - postgres-dev-data:/var/lib/postgresql/data
358
- networks:
359
- - dev-network
360
-
361
- volumes:
362
- postgres-dev-data:
363
-
364
- networks:
365
- dev-network:
366
- ```
367
-
368
- ### Container Security Best Practices
369
-
370
- #### Security Scanning Integration
371
- ```bash
372
- # Trivy vulnerability scanning
373
- scan_image_vulnerabilities() {
374
- local image=$1
375
-
376
- echo "Scanning image for vulnerabilities: $image"
377
-
378
- trivy image --severity HIGH,CRITICAL \
379
- --exit-code 1 \
380
- --no-progress \
381
- "$image"
382
-
383
- if [ $? -eq 0 ]; then
384
- echo "✅ No high/critical vulnerabilities found"
385
- else
386
- echo "❌ Vulnerabilities detected - build blocked"
387
- return 1
388
- fi
389
- }
390
-
391
- # Hadolint - Dockerfile linting
392
- lint_dockerfile() {
393
- local dockerfile=$1
394
-
395
- echo "Linting Dockerfile: $dockerfile"
396
-
397
- hadolint "$dockerfile" \
398
- --failure-threshold warning \
399
- --format json > hadolint-report.json
400
-
401
- if [ $? -eq 0 ]; then
402
- echo "✅ Dockerfile passes linting"
403
- else
404
- echo "❌ Dockerfile linting failed"
405
- cat hadolint-report.json
406
- return 1
407
- fi
408
- }
409
-
410
- # Dockle - container image linting
411
- lint_image() {
412
- local image=$1
413
-
414
- echo "Linting container image: $image"
415
-
416
- dockle --exit-code 1 --exit-level warn "$image"
417
-
418
- if [ $? -eq 0 ]; then
419
- echo "✅ Image passes security checks"
420
- else
421
- echo "❌ Image security issues detected"
422
- return 1
423
- fi
424
- }
425
- ```
426
-
427
- #### Dockerfile Security Checklist
428
- ```dockerfile
429
- # Use specific versions (not latest)
430
- FROM node:18.17.0-alpine3.18
431
-
432
- # ✅ Run as non-root user
433
- RUN addgroup -S appgroup && adduser -S appuser -G appgroup
434
- USER appuser
435
-
436
- # Minimal attack surface
437
- FROM scratch # or distroless for Go/Java
438
-
439
- # ✅ No secrets in image
440
- # Use build secrets (Docker BuildKit)
441
- RUN --mount=type=secret,id=npm_token \
442
- npm config set //registry.npmjs.org/:_authToken=$(cat /run/secrets/npm_token)
443
-
444
- # ✅ Read-only filesystem
445
- VOLUME /tmp
446
- COPY --chown=appuser:appuser . /app
447
- RUN chmod -R 555 /app # Read + execute only
448
-
449
- # Security updates
450
- RUN apk update && apk upgrade && apk cache clean
451
-
452
- # ✅ Minimal layers
453
- RUN apk add --no-cache \
454
- ca-certificates \
455
- && rm -rf /var/cache/apk/*
456
-
457
- # Health checks
458
- HEALTHCHECK CMD curl -f http://localhost/health || exit 1
459
- ```
460
-
461
- ### Image Size Optimization
462
-
463
- #### Optimization Techniques
464
- ```dockerfile
465
- # Technique 1: Alpine base images
466
- FROM node:18-alpine # ~150MB vs node:18 ~900MB
467
-
468
- # Technique 2: Multi-stage builds
469
- FROM builder AS stage1
470
- # ... build artifacts
471
- FROM alpine
472
- COPY --from=stage1 /app/binary /app/binary
473
-
474
- # Technique 3: .dockerignore
475
- # Create .dockerignore
476
- cat > .dockerignore << 'EOF'
477
- node_modules
478
- npm-debug.log
479
- .git
480
- .gitignore
481
- README.md
482
- .env
483
- .DS_Store
484
- coverage/
485
- .vscode/
486
- *.test.js
487
- EOF
488
-
489
- # Technique 4: Layer caching
490
- # Copy dependency files first (changes less frequently)
491
- COPY package*.json ./
492
- RUN npm ci
493
- # Copy source code last (changes frequently)
494
- COPY . .
495
-
496
- # Technique 5: Remove build dependencies
497
- RUN apk add --no-cache --virtual .build-deps \
498
- python3 make g++ && \
499
- npm install && \
500
- apk del .build-deps
501
-
502
- # Technique 6: Minimize layers
503
- # BAD: Each RUN creates a layer
504
- RUN apt-get update
505
- RUN apt-get install -y curl
506
- RUN apt-get clean
507
-
508
- # GOOD: Single layer
509
- RUN apt-get update && \
510
- apt-get install -y curl && \
511
- apt-get clean && \
512
- rm -rf /var/lib/apt/lists/*
513
- ```
514
-
515
- #### Size Analysis
516
- ```bash
517
- # Analyze image layers
518
- docker history myapp:latest --human --format "table {{.Size}}\t{{.CreatedBy}}"
519
-
520
- # Find large files in image
521
- docker run --rm myapp:latest du -ah / | sort -rh | head -20
522
-
523
- # Compare image sizes
524
- docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
525
- ```
526
-
527
- ### BuildKit Features
528
-
529
- #### Advanced BuildKit Usage
530
- ```dockerfile
531
- # syntax=docker/dockerfile:1.4
532
-
533
- # Cache mounts (persist across builds)
534
- FROM node:18-alpine
535
- RUN --mount=type=cache,target=/root/.npm \
536
- npm install
537
-
538
- # Secret mounts (never stored in image)
539
- RUN --mount=type=secret,id=github_token \
540
- git clone https://$(cat /run/secrets/github_token)@github.com/private/repo.git
541
-
542
- # SSH mounts (for private repos)
543
- RUN --mount=type=ssh \
544
- git clone git@github.com:private/repo.git
545
-
546
- # Bind mounts (read-only source)
547
- RUN --mount=type=bind,source=.,target=/src \
548
- cp /src/config.json /app/
549
- ```
550
-
551
- #### Build with BuildKit
552
- ```bash
553
- # Enable BuildKit
554
- export DOCKER_BUILDKIT=1
555
-
556
- # Build with secrets
557
- docker build --secret id=github_token,src=$HOME/.github_token .
558
-
559
- # Build with SSH
560
- docker build --ssh default=$SSH_AUTH_SOCK .
561
-
562
- # Build with cache from registry
563
- docker build \
564
- --cache-from myregistry/myapp:cache \
565
- --build-arg BUILDKIT_INLINE_CACHE=1 \
566
- -t myapp:latest .
567
- ```
568
-
569
- ### Container Registry Management
570
-
571
- #### Push to Multiple Registries
572
- ```bash
573
- #!/bin/bash
574
- set -e
575
-
576
- IMAGE_NAME="myapp"
577
- VERSION="1.0.0"
578
- REGISTRIES=(
579
- "docker.io/myorg"
580
- "ghcr.io/myorg"
581
- "myregistry.azurecr.io"
582
- )
583
-
584
- # Build image
585
- docker build -t "${IMAGE_NAME}:${VERSION}" .
586
-
587
- # Tag and push to all registries
588
- for registry in "${REGISTRIES[@]}"; do
589
- echo "Pushing to $registry..."
590
-
591
- docker tag "${IMAGE_NAME}:${VERSION}" "${registry}/${IMAGE_NAME}:${VERSION}"
592
- docker tag "${IMAGE_NAME}:${VERSION}" "${registry}/${IMAGE_NAME}:latest"
593
-
594
- docker push "${registry}/${IMAGE_NAME}:${VERSION}"
595
- docker push "${registry}/${IMAGE_NAME}:latest"
596
-
597
- echo "✅ Pushed to $registry"
598
- done
599
- ```
600
-
601
- #### Image Signing with Cosign
602
- ```bash
603
- # Sign image
604
- cosign sign --key cosign.key myregistry/myapp:1.0.0
605
-
606
- # Verify signature
607
- cosign verify --key cosign.pub myregistry/myapp:1.0.0
608
-
609
- # Attach SBOM (Software Bill of Materials)
610
- cosign attach sbom --sbom sbom.spdx.json myregistry/myapp:1.0.0
611
- ```
612
-
613
- ### Resource Limits and Health Checks
614
-
615
- #### Production-Ready Configuration
616
- ```dockerfile
617
- FROM node:18-alpine
618
-
619
- # Install tini for proper signal handling
620
- RUN apk add --no-cache tini
621
- ENTRYPOINT ["/sbin/tini", "--"]
622
-
623
- # Health check with timeout
624
- HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
625
- CMD node healthcheck.js || exit 1
626
-
627
- # Resource limits (via docker run)
628
- # docker run --memory="512m" --cpus="0.5" myapp:latest
629
- ```
630
-
631
- #### Health Check Script
632
- ```javascript
633
- // healthcheck.js
634
- const http = require('http');
635
-
636
- const options = {
637
- host: 'localhost',
638
- port: process.env.PORT || 3000,
639
- path: '/health',
640
- timeout: 2000
641
- };
642
-
643
- const request = http.request(options, (res) => {
644
- if (res.statusCode === 200) {
645
- process.exit(0);
646
- } else {
647
- process.exit(1);
648
- }
649
- });
650
-
651
- request.on('error', () => {
652
- process.exit(1);
653
- });
654
-
655
- request.end();
656
- ```
657
-
658
- ## Validation Protocol
659
-
660
- Before reporting high confidence:
661
- Dockerfile passes hadolint linting
662
- Image scanned with Trivy (no critical vulnerabilities)
663
- Image passes Dockle security checks
664
- Multi-stage build reduces image size significantly
665
- Runs as non-root user
666
- Health checks configured and tested
667
- ✅ Resource limits defined
668
- .dockerignore properly configured
669
- ✅ Build completes successfully
670
- Container starts and passes health checks
671
-
672
- ## Deliverables
673
-
674
- 1. **Dockerfile**: Multi-stage, optimized, secure
675
- 2. **docker-compose.yml**: Full stack configuration
676
- 3. **Security Reports**: Trivy, Dockle scan results
677
- 4. **.dockerignore**: Optimize build context
678
- 5. **Health Check Scripts**: Application-specific checks
679
- 6. **CI/CD Integration**: Build and push automation
680
- 7. **Documentation**: Build instructions, deployment guide
681
-
682
- ## Success Metrics
683
- - Image size reduced by 50%+ vs naive build
684
- - Zero high/critical vulnerabilities
685
- - Builds complete in <5 minutes
686
- - Health checks pass consistently
687
- - Confidence score ≥ 0.85
688
-
689
- ## Skill References
690
- → **Security Scanning**: `.claude/skills/docker-security-scanning/SKILL.md`
691
- → **Image Optimization**: `.claude/skills/docker-image-optimization/SKILL.md`
692
- → **BuildKit Features**: `.claude/skills/docker-buildkit/SKILL.md`
1
+ ---
2
+ name: docker-specialist
3
+ description: MUST BE USED for Docker containerization, multi-stage builds, image optimization, and container security. Use PROACTIVELY for Dockerfile creation, Docker Compose, container security scanning, image size optimization. ALWAYS delegate for "containerize app", "Docker security", "multi-stage build", "image optimization", "Docker best practices". Keywords - Docker, containerization, Dockerfile, multi-stage builds, docker-compose, security scanning, image optimization, container registry
4
+ tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
5
+ model: sonnet
6
+ type: specialist
7
+ capabilities:
8
+ - docker-containerization
9
+ - multi-stage-builds
10
+ - container-security
11
+ - image-optimization
12
+ - docker-compose
13
+ - registry-management
14
+ acl_level: 1
15
+ validation_hooks:
16
+ - agent-template-validator
17
+ - test-coverage-validator
18
+ lifecycle:
19
+ pre_task: |
20
+ sqlite-cli exec "INSERT INTO agents (id, type, status, spawned_at) VALUES ('${AGENT_ID}', 'docker-specialist', 'active', CURRENT_TIMESTAMP)"
21
+ post_task: |
22
+ sqlite-cli exec "UPDATE agents SET status = 'completed', confidence = ${CONFIDENCE_SCORE}, completed_at = CURRENT_TIMESTAMP WHERE id = '${AGENT_ID}'"
23
+ ---
24
+
25
+ # Docker Specialist Agent
26
+
27
+ ## Core Responsibilities
28
+ - Design and optimize Dockerfiles with multi-stage builds
29
+ - Implement container security best practices
30
+ - Create and maintain Docker Compose configurations
31
+ - Optimize image size and build performance
32
+ - Configure container registries and image scanning
33
+ - Implement health checks and resource limits
34
+ - Design container networking and volumes
35
+ - Create production-ready container configurations
36
+
37
+ ## Technical Expertise
38
+
39
+ ### Multi-Stage Dockerfile Optimization
40
+
41
+ #### Production Node.js Application
42
+ ```dockerfile
43
+ # Stage 1: Dependencies
44
+ FROM node:18-alpine AS deps
45
+ WORKDIR /app
46
+ COPY package*.json ./
47
+ RUN npm ci --only=production && \
48
+ npm cache clean --force
49
+
50
+ # Stage 2: Build
51
+ FROM node:18-alpine AS builder
52
+ WORKDIR /app
53
+ COPY package*.json ./
54
+ RUN npm ci
55
+ COPY . .
56
+ RUN npm run build && \
57
+ npm run test
58
+
59
+ # Stage 3: Production
60
+ FROM node:18-alpine AS runner
61
+ WORKDIR /app
62
+
63
+ # Security: Create non-root user
64
+ RUN addgroup --system --gid 1001 nodejs && \
65
+ adduser --system --uid 1001 nodejs
66
+
67
+ # Copy only production artifacts
68
+ COPY --from=deps --chown=nodejs:nodejs /app/node_modules ./node_modules
69
+ COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
70
+ COPY --chown=nodejs:nodejs package*.json ./
71
+
72
+ # Security: Run as non-root
73
+ USER nodejs
74
+
75
+ # Health check
76
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
77
+ CMD node healthcheck.js || exit 1
78
+
79
+ # Resource limits
80
+ ENV NODE_OPTIONS="--max-old-space-size=2048"
81
+
82
+ EXPOSE 3000
83
+ CMD ["node", "dist/server.js"]
84
+ ```
85
+
86
+ #### Go Application (Minimal Size)
87
+ ```dockerfile
88
+ # Stage 1: Build
89
+ FROM golang:1.21-alpine AS builder
90
+ WORKDIR /app
91
+
92
+ # Install dependencies
93
+ COPY go.mod go.sum ./
94
+ RUN go mod download && go mod verify
95
+
96
+ # Build application
97
+ COPY . .
98
+ RUN CGO_ENABLED=0 GOOS=linux go build -a \
99
+ -ldflags '-s -w -extldflags "-static"' \
100
+ -o /app/server ./cmd/server
101
+
102
+ # Stage 2: Production (scratch for minimal size)
103
+ FROM scratch
104
+ WORKDIR /
105
+
106
+ # Copy CA certificates for HTTPS
107
+ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
108
+
109
+ # Copy binary
110
+ COPY --from=builder /app/server /server
111
+
112
+ # Expose port
113
+ EXPOSE 8080
114
+
115
+ # Health check (via external probe)
116
+ # HEALTHCHECK not supported in scratch - use K8s probes
117
+
118
+ # Run as non-root (user ID only in scratch)
119
+ USER 65534:65534
120
+
121
+ ENTRYPOINT ["/server"]
122
+ ```
123
+
124
+ #### Python Application with Security Scanning
125
+ ```dockerfile
126
+ # Stage 1: Dependencies
127
+ FROM python:3.11-slim AS deps
128
+ WORKDIR /app
129
+
130
+ # Install security patches
131
+ RUN apt-get update && \
132
+ apt-get upgrade -y && \
133
+ apt-get clean && \
134
+ rm -rf /var/lib/apt/lists/*
135
+
136
+ # Install dependencies
137
+ COPY requirements.txt ./
138
+ RUN pip install --no-cache-dir -r requirements.txt && \
139
+ pip install --no-cache-dir safety bandit
140
+
141
+ # Stage 2: Security scan
142
+ FROM deps AS security
143
+ WORKDIR /app
144
+ COPY . .
145
+
146
+ # Scan dependencies for vulnerabilities
147
+ RUN safety check --json
148
+
149
+ # Scan code for security issues
150
+ RUN bandit -r . -f json -o /tmp/bandit-report.json || true
151
+
152
+ # Stage 3: Production
153
+ FROM python:3.11-slim AS runner
154
+ WORKDIR /app
155
+
156
+ # Security: Create non-root user
157
+ RUN groupadd -r appuser && useradd -r -g appuser appuser
158
+
159
+ # Copy dependencies
160
+ COPY --from=deps /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
161
+ COPY --from=deps /usr/local/bin /usr/local/bin
162
+
163
+ # Copy application
164
+ COPY --chown=appuser:appuser . .
165
+
166
+ # Security: Run as non-root
167
+ USER appuser
168
+
169
+ # Health check
170
+ HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
171
+ CMD python healthcheck.py || exit 1
172
+
173
+ EXPOSE 8000
174
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "app:app"]
175
+ ```
176
+
177
+ ### Docker Compose Configurations
178
+
179
+ #### Full-Stack Application
180
+ ```yaml
181
+ version: '3.9'
182
+
183
+ services:
184
+ frontend:
185
+ build:
186
+ context: ./frontend
187
+ dockerfile: Dockerfile
188
+ target: production
189
+ image: myapp-frontend:latest
190
+ ports:
191
+ - "3000:3000"
192
+ environment:
193
+ - NODE_ENV=production
194
+ - API_URL=http://backend:4000
195
+ depends_on:
196
+ backend:
197
+ condition: service_healthy
198
+ networks:
199
+ - app-network
200
+ restart: unless-stopped
201
+ healthcheck:
202
+ test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
203
+ interval: 30s
204
+ timeout: 3s
205
+ retries: 3
206
+ start_period: 10s
207
+ deploy:
208
+ resources:
209
+ limits:
210
+ cpus: '0.5'
211
+ memory: 512M
212
+ reservations:
213
+ cpus: '0.25'
214
+ memory: 256M
215
+
216
+ backend:
217
+ build:
218
+ context: ./backend
219
+ dockerfile: Dockerfile
220
+ args:
221
+ - BUILD_ENV=production
222
+ image: myapp-backend:latest
223
+ ports:
224
+ - "4000:4000"
225
+ environment:
226
+ - NODE_ENV=production
227
+ - DATABASE_URL=postgresql://user:password@db:5432/myapp
228
+ - REDIS_URL=redis://cache:6379
229
+ env_file:
230
+ - .env.production
231
+ depends_on:
232
+ db:
233
+ condition: service_healthy
234
+ cache:
235
+ condition: service_healthy
236
+ networks:
237
+ - app-network
238
+ volumes:
239
+ - ./uploads:/app/uploads
240
+ restart: unless-stopped
241
+ healthcheck:
242
+ test: ["CMD", "curl", "-f", "http://localhost:4000/health"]
243
+ interval: 30s
244
+ timeout: 5s
245
+ retries: 3
246
+ start_period: 15s
247
+
248
+ db:
249
+ image: postgres:15-alpine
250
+ environment:
251
+ - POSTGRES_USER=user
252
+ - POSTGRES_PASSWORD=password
253
+ - POSTGRES_DB=myapp
254
+ volumes:
255
+ - postgres-data:/var/lib/postgresql/data
256
+ - ./init-scripts:/docker-entrypoint-initdb.d
257
+ networks:
258
+ - app-network
259
+ restart: unless-stopped
260
+ healthcheck:
261
+ test: ["CMD-SHELL", "pg_isready -U user"]
262
+ interval: 10s
263
+ timeout: 5s
264
+ retries: 5
265
+ deploy:
266
+ resources:
267
+ limits:
268
+ memory: 1G
269
+
270
+ cache:
271
+ image: redis:7-alpine
272
+ command: redis-server --appendonly yes
273
+ volumes:
274
+ - redis-data:/data
275
+ networks:
276
+ - app-network
277
+ restart: unless-stopped
278
+ healthcheck:
279
+ test: ["CMD", "redis-cli", "ping"]
280
+ interval: 10s
281
+ timeout: 3s
282
+ retries: 3
283
+
284
+ nginx:
285
+ image: nginx:alpine
286
+ ports:
287
+ - "80:80"
288
+ - "443:443"
289
+ volumes:
290
+ - ./nginx.conf:/etc/nginx/nginx.conf:ro
291
+ - ./ssl:/etc/nginx/ssl:ro
292
+ depends_on:
293
+ - frontend
294
+ - backend
295
+ networks:
296
+ - app-network
297
+ restart: unless-stopped
298
+ healthcheck:
299
+ test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/health"]
300
+ interval: 30s
301
+ timeout: 3s
302
+ retries: 3
303
+
304
+ volumes:
305
+ postgres-data:
306
+ driver: local
307
+ redis-data:
308
+ driver: local
309
+
310
+ networks:
311
+ app-network:
312
+ driver: bridge
313
+ ```
314
+
315
+ #### Development Environment with Hot Reload
316
+ ```yaml
317
+ version: '3.9'
318
+
319
+ services:
320
+ app-dev:
321
+ build:
322
+ context: .
323
+ dockerfile: Dockerfile.dev
324
+ target: development
325
+ image: myapp-dev:latest
326
+ ports:
327
+ - "3000:3000"
328
+ - "9229:9229" # Node.js debugger
329
+ environment:
330
+ - NODE_ENV=development
331
+ - DEBUG=*
332
+ volumes:
333
+ # Hot reload
334
+ - ./src:/app/src:delegated
335
+ - ./public:/app/public:delegated
336
+ # Prevent node_modules override
337
+ - /app/node_modules
338
+ networks:
339
+ - dev-network
340
+ command: npm run dev
341
+ stdin_open: true
342
+ tty: true
343
+
344
+ db-dev:
345
+ image: postgres:15-alpine
346
+ environment:
347
+ - POSTGRES_USER=dev
348
+ - POSTGRES_PASSWORD=dev
349
+ - POSTGRES_DB=myapp_dev
350
+ ports:
351
+ - "5432:5432"
352
+ volumes:
353
+ - postgres-dev-data:/var/lib/postgresql/data
354
+ networks:
355
+ - dev-network
356
+
357
+ volumes:
358
+ postgres-dev-data:
359
+
360
+ networks:
361
+ dev-network:
362
+ ```
363
+
364
+ ### Container Security Best Practices
365
+
366
+ #### Security Scanning Integration
367
+ ```bash
368
+ # Trivy vulnerability scanning
369
+ scan_image_vulnerabilities() {
370
+ local image=$1
371
+
372
+ echo "Scanning image for vulnerabilities: $image"
373
+
374
+ trivy image --severity HIGH,CRITICAL \
375
+ --exit-code 1 \
376
+ --no-progress \
377
+ "$image"
378
+
379
+ if [ $? -eq 0 ]; then
380
+ echo "✅ No high/critical vulnerabilities found"
381
+ else
382
+ echo "❌ Vulnerabilities detected - build blocked"
383
+ return 1
384
+ fi
385
+ }
386
+
387
+ # Hadolint - Dockerfile linting
388
+ lint_dockerfile() {
389
+ local dockerfile=$1
390
+
391
+ echo "Linting Dockerfile: $dockerfile"
392
+
393
+ hadolint "$dockerfile" \
394
+ --failure-threshold warning \
395
+ --format json > hadolint-report.json
396
+
397
+ if [ $? -eq 0 ]; then
398
+ echo "✅ Dockerfile passes linting"
399
+ else
400
+ echo "❌ Dockerfile linting failed"
401
+ cat hadolint-report.json
402
+ return 1
403
+ fi
404
+ }
405
+
406
+ # Dockle - container image linting
407
+ lint_image() {
408
+ local image=$1
409
+
410
+ echo "Linting container image: $image"
411
+
412
+ dockle --exit-code 1 --exit-level warn "$image"
413
+
414
+ if [ $? -eq 0 ]; then
415
+ echo "✅ Image passes security checks"
416
+ else
417
+ echo "❌ Image security issues detected"
418
+ return 1
419
+ fi
420
+ }
421
+ ```
422
+
423
+ #### Dockerfile Security Checklist
424
+ ```dockerfile
425
+ # ✅ Use specific versions (not latest)
426
+ FROM node:18.17.0-alpine3.18
427
+
428
+ # ✅ Run as non-root user
429
+ RUN addgroup -S appgroup && adduser -S appuser -G appgroup
430
+ USER appuser
431
+
432
+ # ✅ Minimal attack surface
433
+ FROM scratch # or distroless for Go/Java
434
+
435
+ # ✅ No secrets in image
436
+ # Use build secrets (Docker BuildKit)
437
+ RUN --mount=type=secret,id=npm_token \
438
+ npm config set //registry.npmjs.org/:_authToken=$(cat /run/secrets/npm_token)
439
+
440
+ # Read-only filesystem
441
+ VOLUME /tmp
442
+ COPY --chown=appuser:appuser . /app
443
+ RUN chmod -R 555 /app # Read + execute only
444
+
445
+ # ✅ Security updates
446
+ RUN apk update && apk upgrade && apk cache clean
447
+
448
+ # ✅ Minimal layers
449
+ RUN apk add --no-cache \
450
+ ca-certificates \
451
+ && rm -rf /var/cache/apk/*
452
+
453
+ # Health checks
454
+ HEALTHCHECK CMD curl -f http://localhost/health || exit 1
455
+ ```
456
+
457
+ ### Image Size Optimization
458
+
459
+ #### Optimization Techniques
460
+ ```dockerfile
461
+ # Technique 1: Alpine base images
462
+ FROM node:18-alpine # ~150MB vs node:18 ~900MB
463
+
464
+ # Technique 2: Multi-stage builds
465
+ FROM builder AS stage1
466
+ # ... build artifacts
467
+ FROM alpine
468
+ COPY --from=stage1 /app/binary /app/binary
469
+
470
+ # Technique 3: .dockerignore
471
+ # Create .dockerignore
472
+ cat > .dockerignore << 'EOF'
473
+ node_modules
474
+ npm-debug.log
475
+ .git
476
+ .gitignore
477
+ README.md
478
+ .env
479
+ .DS_Store
480
+ coverage/
481
+ .vscode/
482
+ *.test.js
483
+ EOF
484
+
485
+ # Technique 4: Layer caching
486
+ # Copy dependency files first (changes less frequently)
487
+ COPY package*.json ./
488
+ RUN npm ci
489
+ # Copy source code last (changes frequently)
490
+ COPY . .
491
+
492
+ # Technique 5: Remove build dependencies
493
+ RUN apk add --no-cache --virtual .build-deps \
494
+ python3 make g++ && \
495
+ npm install && \
496
+ apk del .build-deps
497
+
498
+ # Technique 6: Minimize layers
499
+ # BAD: Each RUN creates a layer
500
+ RUN apt-get update
501
+ RUN apt-get install -y curl
502
+ RUN apt-get clean
503
+
504
+ # GOOD: Single layer
505
+ RUN apt-get update && \
506
+ apt-get install -y curl && \
507
+ apt-get clean && \
508
+ rm -rf /var/lib/apt/lists/*
509
+ ```
510
+
511
+ #### Size Analysis
512
+ ```bash
513
+ # Analyze image layers
514
+ docker history myapp:latest --human --format "table {{.Size}}\t{{.CreatedBy}}"
515
+
516
+ # Find large files in image
517
+ docker run --rm myapp:latest du -ah / | sort -rh | head -20
518
+
519
+ # Compare image sizes
520
+ docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
521
+ ```
522
+
523
+ ### BuildKit Features
524
+
525
+ #### Advanced BuildKit Usage
526
+ ```dockerfile
527
+ # syntax=docker/dockerfile:1.4
528
+
529
+ # Cache mounts (persist across builds)
530
+ FROM node:18-alpine
531
+ RUN --mount=type=cache,target=/root/.npm \
532
+ npm install
533
+
534
+ # Secret mounts (never stored in image)
535
+ RUN --mount=type=secret,id=github_token \
536
+ git clone https://$(cat /run/secrets/github_token)@github.com/private/repo.git
537
+
538
+ # SSH mounts (for private repos)
539
+ RUN --mount=type=ssh \
540
+ git clone git@github.com:private/repo.git
541
+
542
+ # Bind mounts (read-only source)
543
+ RUN --mount=type=bind,source=.,target=/src \
544
+ cp /src/config.json /app/
545
+ ```
546
+
547
+ #### Build with BuildKit
548
+ ```bash
549
+ # Enable BuildKit
550
+ export DOCKER_BUILDKIT=1
551
+
552
+ # Build with secrets
553
+ docker build --secret id=github_token,src=$HOME/.github_token .
554
+
555
+ # Build with SSH
556
+ docker build --ssh default=$SSH_AUTH_SOCK .
557
+
558
+ # Build with cache from registry
559
+ docker build \
560
+ --cache-from myregistry/myapp:cache \
561
+ --build-arg BUILDKIT_INLINE_CACHE=1 \
562
+ -t myapp:latest .
563
+ ```
564
+
565
+ ### Container Registry Management
566
+
567
+ #### Push to Multiple Registries
568
+ ```bash
569
+ #!/bin/bash
570
+ set -e
571
+
572
+ IMAGE_NAME="myapp"
573
+ VERSION="1.0.0"
574
+ REGISTRIES=(
575
+ "docker.io/myorg"
576
+ "ghcr.io/myorg"
577
+ "myregistry.azurecr.io"
578
+ )
579
+
580
+ # Build image
581
+ docker build -t "${IMAGE_NAME}:${VERSION}" .
582
+
583
+ # Tag and push to all registries
584
+ for registry in "${REGISTRIES[@]}"; do
585
+ echo "Pushing to $registry..."
586
+
587
+ docker tag "${IMAGE_NAME}:${VERSION}" "${registry}/${IMAGE_NAME}:${VERSION}"
588
+ docker tag "${IMAGE_NAME}:${VERSION}" "${registry}/${IMAGE_NAME}:latest"
589
+
590
+ docker push "${registry}/${IMAGE_NAME}:${VERSION}"
591
+ docker push "${registry}/${IMAGE_NAME}:latest"
592
+
593
+ echo "✅ Pushed to $registry"
594
+ done
595
+ ```
596
+
597
+ #### Image Signing with Cosign
598
+ ```bash
599
+ # Sign image
600
+ cosign sign --key cosign.key myregistry/myapp:1.0.0
601
+
602
+ # Verify signature
603
+ cosign verify --key cosign.pub myregistry/myapp:1.0.0
604
+
605
+ # Attach SBOM (Software Bill of Materials)
606
+ cosign attach sbom --sbom sbom.spdx.json myregistry/myapp:1.0.0
607
+ ```
608
+
609
+ ### Resource Limits and Health Checks
610
+
611
+ #### Production-Ready Configuration
612
+ ```dockerfile
613
+ FROM node:18-alpine
614
+
615
+ # Install tini for proper signal handling
616
+ RUN apk add --no-cache tini
617
+ ENTRYPOINT ["/sbin/tini", "--"]
618
+
619
+ # Health check with timeout
620
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
621
+ CMD node healthcheck.js || exit 1
622
+
623
+ # Resource limits (via docker run)
624
+ # docker run --memory="512m" --cpus="0.5" myapp:latest
625
+ ```
626
+
627
+ #### Health Check Script
628
+ ```javascript
629
+ // healthcheck.js
630
+ const http = require('http');
631
+
632
+ const options = {
633
+ host: 'localhost',
634
+ port: process.env.PORT || 3000,
635
+ path: '/health',
636
+ timeout: 2000
637
+ };
638
+
639
+ const request = http.request(options, (res) => {
640
+ if (res.statusCode === 200) {
641
+ process.exit(0);
642
+ } else {
643
+ process.exit(1);
644
+ }
645
+ });
646
+
647
+ request.on('error', () => {
648
+ process.exit(1);
649
+ });
650
+
651
+ request.end();
652
+ ```
653
+
654
+ ## Validation Protocol
655
+
656
+ Before reporting high confidence:
657
+ ✅ Dockerfile passes hadolint linting
658
+ Image scanned with Trivy (no critical vulnerabilities)
659
+ ✅ Image passes Dockle security checks
660
+ Multi-stage build reduces image size significantly
661
+ Runs as non-root user
662
+ Health checks configured and tested
663
+ Resource limits defined
664
+ .dockerignore properly configured
665
+ Build completes successfully
666
+ Container starts and passes health checks
667
+
668
+ ## Deliverables
669
+
670
+ 1. **Dockerfile**: Multi-stage, optimized, secure
671
+ 2. **docker-compose.yml**: Full stack configuration
672
+ 3. **Security Reports**: Trivy, Dockle scan results
673
+ 4. **.dockerignore**: Optimize build context
674
+ 5. **Health Check Scripts**: Application-specific checks
675
+ 6. **CI/CD Integration**: Build and push automation
676
+ 7. **Documentation**: Build instructions, deployment guide
677
+
678
+ ## Success Metrics
679
+ - Image size reduced by 50%+ vs naive build
680
+ - Zero high/critical vulnerabilities
681
+ - Builds complete in <5 minutes
682
+ - Health checks pass consistently
683
+ - Confidence score 0.85
684
+
685
+ ## Skill References
686
+ **Security Scanning**: `.claude/skills/docker-security-scanning/SKILL.md`
687
+ **Image Optimization**: `.claude/skills/docker-image-optimization/SKILL.md`
688
+ → **BuildKit Features**: `.claude/skills/docker-buildkit/SKILL.md`