About docker-patterns
A collection of patterns for Docker containerization, intended for developers building images and configuring containers. It covers multi-stage builds, image security, health checks, and Compose configuration.
Key features
- 01Reduce image size with multi-stage builds
- 02Run containers as a non-root user
- 03Pin version tags and scan images
- 04Exclude sensitive files with `.dockerignore`
- 05Configure container health checks
Use cases
- 01Build a smaller production image for an application
- 02Review image and container security practices
- 03Add health checks and Compose configuration to services
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ langchain-ai/ skills-benchmarks --skill docker-patternsAfter installing, type/docker-patternsin Claude Code to confirm it loaded.
Details
From the project READMEDocker Containerization Patterns
Build efficient, secure Docker images using modern patterns.
Multi-Stage Builds
Always use multi-stage builds to minimize image size:
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
# Production stage
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY . .
USER node
CMD ["node", "server.js"]
Security Best Practices
- Never run as root - use
USERdirective - Use specific version tags, not
latest - Scan images with
docker scoutor Trivy - Use
.dockerignoreto exclude sensitive files
Health Checks
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
Compose Patterns
services:
app:
build:
context: .
target: production
environment:
- NODE_ENV=production
deploy:
resources:
limits:
memory: 512M
Comments
Markdown supported