docker-patterns
Docker best practices, multi-stage builds, container security, Docker Compose orchestration, and deployment patterns. Use when containerizing applications, optimizing Docker images, setting up development environments, or deploying with Docker.
Best use case
docker-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Docker best practices, multi-stage builds, container security, Docker Compose orchestration, and deployment patterns. Use when containerizing applications, optimizing Docker images, setting up development environments, or deploying with Docker.
Teams using docker-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/docker-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How docker-patterns Compares
| Feature / Agent | docker-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Docker best practices, multi-stage builds, container security, Docker Compose orchestration, and deployment patterns. Use when containerizing applications, optimizing Docker images, setting up development environments, or deploying with Docker.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Docker Patterns Skill
## Overview
This skill provides guidelines for building production-ready Docker containers, multi-stage builds, security hardening, Docker Compose orchestration, and deployment best practices.
## Quick Reference
### Multi-Stage Build Example
```dockerfile
# Build stage
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production stage
FROM node:18-alpine
RUN addgroup -g 1001 -S nodejs && adduser -S nodejs -u 1001
WORKDIR /app
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
USER nodejs
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
CMD ["node", "dist/main.js"]
```
### Docker Compose Development
```yaml
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
volumes:
- .:/app
- /app/node_modules
environment:
- NODE_ENV=development
```
## Core Principles
### 1. Multi-Stage Builds
- Separate build and runtime environments
- Minimize final image size
- Don't include build tools in production
### 2. Security Hardening
- Run as non-root user
- Use specific image tags (not `latest`)
- Scan images for vulnerabilities
- Drop unnecessary capabilities
### 3. Layer Caching
- Order instructions by change frequency
- Copy package files before source code
- Use `.dockerignore` to exclude unnecessary files
### 4. Health Checks
- Implement `/health` endpoints
- Configure Docker health checks
- Set appropriate intervals and timeouts
## Language-Specific Examples
See detailed guides in references/:
- **[Dockerfile Patterns](references/dockerfile-patterns.md)** - Multi-stage builds for Node.js, Python, Go, Rust
- **[Docker Compose Patterns](references/docker-compose-patterns.md)** - Development, production, and multi-environment setups
- **[Container Security](references/container-security.md)** - Security hardening, scanning, and best practices
- **[Deployment Patterns](references/deployment-patterns.md)** - Blue-green, rolling updates, Kubernetes
## Dockerfile Best Practices
```dockerfile
# ✅ DO: Use specific tags
FROM node:18.19.0-alpine3.18
# ✅ DO: Combine RUN commands
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/*
# ✅ DO: Create non-root user
RUN addgroup -g 1001 -S appgroup && \
adduser -S appuser -u 1001 -G appgroup
USER appuser
# ✅ DO: Copy with ownership
COPY --chown=appuser:appgroup . /app
# ✅ DO: Add health check
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost:3000/health || exit 1
```
## Docker Compose Best Practices
```yaml
# ✅ DO: Use environment files
services:
app:
env_file:
- .env.production
# ✅ DO: Set resource limits
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
# ✅ DO: Configure health checks
healthcheck:
test: ["CMD", "wget", "--spider", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
```
## Image Scanning
```bash
# Using Trivy
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
aquasec/trivy:latest image myapp:latest
# Using Docker Scout
docker scout cves myapp:latest
# Using Snyk
snyk container test myapp:latest
```
## When to Use This Skill
Use this skill when:
- Creating Dockerfiles for production applications
- Setting up development environments with Docker Compose
- Optimizing image sizes with multi-stage builds
- Hardening containers for security
- Setting up health checks and monitoring
- Managing multiple environments (dev/staging/prod)
- Implementing CI/CD pipelines with Docker
- Troubleshooting container issues
## Related Skills
- `@ci-cd-pipelines` - Continuous integration and deployment with GitHub Actions
- `@security-best-practices` - Container security and vulnerability scanning
- `@feature-development` - Development workflow
- `@python-patterns` - Python-specific patterns
- `@go-conventions` - Go-specific patterns
- `@ts-react-nextjs` - Node.js patternsRelated Skills
fastapi-patterns
FastAPI patterns with Pydantic, async operations, and dependency injection
express-api-patterns
Express.js API development, route handling, middleware, error handling, request validation, CORS. Use when building Express routes, implementing middleware, handling API requests, or setting up the backend server.
error-handling-patterns
Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.
enterprise-architecture-patterns
Complete guide for enterprise architecture patterns including domain-driven design, event sourcing, CQRS, saga patterns, API gateway, service mesh, and scalability
drizzle-patterns
Drizzle ORM patterns for SQLite - queries, relations, and safety guidelines. Use when writing database queries or debugging issues.
dotnet-backend-patterns
Master C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuratio...
dotnet-aspire-patterns
Orchestrates .NET Aspire apps. AppHost, service discovery, components, dashboard, health checks.
docker-compose-networking
Use when configuring networks and service communication in Docker Compose including bridge networks, overlay networks, service discovery, and inter-service communication.
debug-log-patterns
Language-specific debug logging patterns and best practices. Reference when adding instrumentation for Dart/Flutter, Kotlin/Android, Swift/iOS, or JavaScript/TypeScript applications.
ddd-tactical-patterns
Apply DDD tactical patterns in code using entities, value objects, aggregates, repositories, and domain events with explicit invariants.
database-patterns
Use when designing database schemas, implementing repository patterns, writing optimized queries, managing migrations, or working with indexes and transactions for SQL/NoSQL databases.
database-design-patterns
Database schema design patterns and optimization strategies for relational and NoSQL databases. Use when designing database schemas, optimizing query performance, or implementing data persistence layers at scale.