Agent skill
Docker Patterns
Multi-stage builds, security, optimization
Install this agent skill to your Project
npx add-skill https://github.com/Kastalien-Research/thoughtbox-dot-claude/tree/main/.claude/skills/docker
SKILL.md
Docker Development Patterns
Container best practices and security patterns for 2025.
Multi-Stage Builds
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production stage
FROM node:20-alpine AS production
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/index.js"]
Security Best Practices
Non-Root User
FROM node:20-alpine
# Create app user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
WORKDIR /app
COPY --chown=nextjs:nodejs . .
USER nextjs
CMD ["node", "server.js"]
Minimal Base Images
# ✅ Good - Alpine (small, secure)
FROM node:20-alpine
# ❌ Bad - Full Debian (large attack surface)
FROM node:20
Scan for Vulnerabilities
# Scan image
docker scan myapp:latest
# Use Trivy
trivy image myapp:latest
Optimization
Layer Caching
# ✅ Good - Dependencies cached separately
COPY package*.json ./
RUN npm ci
COPY . .
# ❌ Bad - Cache invalidated on any file change
COPY . .
RUN npm ci
.dockerignore
node_modules
npm-debug.log
.git
.env
*.md
.vscode
coverage
dist
.next
Minimize Layers
# ✅ Good - Single RUN
RUN apk add --no-cache git curl && \
npm ci && \
rm -rf /tmp/*
# ❌ Bad - Multiple layers
RUN apk add git
RUN apk add curl
RUN npm ci
Docker Compose
Development Setup
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- .:/app
- /app/node_modules
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- DATABASE_URL=postgres://db:5432/myapp
depends_on:
- db
- redis
db:
image: postgres:15-alpine
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=myapp
ports:
- "5432:5432"
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
postgres_data:
Healthchecks
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node healthcheck.js || exit 1
// healthcheck.js
const http = require('http');
const options = {
host: 'localhost',
port: 3000,
path: '/health',
timeout: 2000
};
const request = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
process.exitCode = (res.statusCode === 200) ? 0 : 1;
process.exit();
});
request.on('error', () => {
console.log('ERROR');
process.exit(1);
});
request.end();
Best Practices
✅ Do:
- Use multi-stage builds
- Run as non-root user
- Use specific image tags (not
latest) - Minimize layers
- Use .dockerignore
- Scan images for vulnerabilities
- Add health checks
- Keep images small
❌ Don't:
- Run as root
- Use
latesttag - Include secrets in images
- Install unnecessary packages
- Copy node_modules into container
- Ignore security scans
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
zod4
Comprehensive guide for Zod 4 schema validation library. This skill should be used when migrating from Zod 3, learning Zod 4 idioms, or building new validation schemas. Covers breaking changes, new features, and migration patterns.
mcp-client-builder
Build production-ready MCP clients in TypeScript or Python. Handles connection lifecycle, transport abstraction, tool orchestration, security, and error handling. Use for integrating LLM applications with MCP servers.
template-skill
Replace with description of the skill and when Claude should use it.
effect-ts
Comprehensive guide for Effect-TS, the functional TypeScript library. Use when building Effect applications, especially MCP servers. Covers correct APIs, common misconceptions, and MCP-specific patterns.
skill-creator
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
Didn't find tool you were looking for?