mcpField
D
docker-patterns

docker-patterns

github.com/langchain-aiCloud & DevOps11956 installsUpdated 10w ago
Repository

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

  1. 01Reduce image size with multi-stage builds
  2. 02Run containers as a non-root user
  3. 03Pin version tags and scan images
  4. 04Exclude sensitive files with `.dockerignore`
  5. 05Configure container health checks

Use cases

  1. 01Build a smaller production image for an application
  2. 02Review image and container security practices
  3. 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-patterns

After installing, type/docker-patternsin Claude Code to confirm it loaded.

Details

From the project README

Docker 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

  1. Never run as root - use USER directive
  2. Use specific version tags, not latest
  3. Scan images with docker scout or Trivy
  4. Use .dockerignore to 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