Command Palette

Search for a command to run...

Назад к скиллам
скилл № 44149

docker-patterns

Use when the user asks to write a Dockerfile, a multi-stage Dockerfile for a Node, Python or Go service, Docker Compose, .dockerignore, non-root containers…

БесплатноБез исполняемых скриптов
j4flmaoот j4flmao★ 47 звёзд на GitHub

Установить docker-patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Docker Patterns

Purpose

Containerize applications following Docker best practices for development and production.

Agent Protocol

Trigger

Exact user phrases: "Dockerfile", "Docker", "Docker Compose", "containerize", "container", "docker build", "multi-stage build", "docker-compose.yml".

Input Context

  • Application stack (for base image selection).
  • Build tooling (for layer caching strategy).
  • Deployment target (for production vs dev separation).
  • Language-specific build requirements (compilers, system deps).

Output Artifact

Writes to Dockerfile, .dockerignore, and/or docker-compose.yml.

Response Format

Dockerfile or docker-compose.yml with comments explaining each section.

No preamble. No postamble. No explanations. No filler/hedging/transitions.

Completion Criteria

  • Multi-stage build is implemented (builder + runner).
  • Non-root user is configured.
  • .dockerignore exists.
  • Layer caching is optimized (dependency files copied first).
  • Health check is configured.
  • Production vs development separation is handled.

Architecture / Decision Trees

Base Image Selection

Base Image Size Security Surface Use Case
alpine ~5MB Minimal (musl libc) Go, Rust, static binaries
slim (debian) ~80MB Reduced (glibc) Node, Python, Ruby
distroless ~15MB Minimal (no shell) Production, security-hardened
ubuntu/debian ~200MB Full (apt, tools) Development, complex deps
scratch 0MB Empty Static Go binaries
windows ~5GB Large Windows containers

Build Strategy Decision Tree

  • Static binary (Go, Rust): scratch or distroless for smallest size.
  • Interpreted (Node, Python, Ruby): slim or distroless.
  • Compile-to-binary (Java, .NET): multi-stage JDK builder -> JRE runner.
  • System dependencies needed: alpine with apk or slim with apt.
  • Development: full image with dev tools + mounted source as volume.
  • Production: minimal image, no shell, no package manager.
  • Security audit required: distroless (no shell, no apt)

Docker Compose Profile Decision Tree

Profile Build Target Volumes Environment Best For
development builder Source mount NODE_ENV=development Active development
testing builder Source mount NODE_ENV=test CI pipeline
staging runner None NODE_ENV=staging Pre-production validation
production runner None NODE_ENV=production Production deployment

Language-Specific Patterns

Language Base Image Multi-Stage Non-Root Caching
Node.js node:22-alpine npm ci in builder, copy dist to runner adduser -D nodeuser COPY package*.json first
Python python:3.12-slim pip install in builder, copy site-packages adduser --disabled-password COPY requirements.txt first
Go golang:1.22-alpine go build in builder, copy binary to scratch USER 65534 COPY go.mod go.sum first
Rust rust:1.77-slim cargo build in builder, copy binary to distroless USER 1000 COPY Cargo.toml Cargo.lock first
Java eclipse-temurin:21-jdk-alpine mvn package in builder, copy jar to jre addgroup -S appgroup COPY pom.xml first

Core Workflow

Step 1: Multi-Stage Dockerfile (Node.js)

# Stage 1: Build
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY tsconfig.json ./
COPY src/ ./src/
RUN npm run build && npm prune --production

# Stage 2: Production
FROM gcr.io/distroless/nodejs22-debian12 AS runner
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
USER nonroot
EXPOSE 3000
ENV NODE_ENV=production
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
  CMD ["node", "-e", "require('http').get('http://localhost:3000/health', r => process.exit(r.statusCode !== 200 ? 1 : 0))"]
CMD ["dist/main.js"]

Step 1b: Multi-Stage Dockerfile (Go)

FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/server .

FROM scratch AS runner
COPY --from=builder /app/server /server
EXPOSE 8080
USER 65534
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD ["/server", "health"]
CMD ["/server"]

Step 2: Layer Caching Optimization

# WRONG: Source code copied first -- cache invalidated on every change
COPY . .
RUN npm ci           # runs every time

# RIGHT: Dependency files copied first -- cached unless package.json changes
COPY package*.json ./
RUN npm ci           # cached unless package.json changes
COPY . .             # only invalidates after this line
RUN npm run build

Step 3: .dockerignore

node_modules
.git
.gitignore
.env
.env.*
*.md
Dockerfile
.dockerignore
.gitlab-ci.yml
.github
dist
.cache
coverage
test-results
*.log
.vscode
.idea

Step 4: Docker Compose with Profiles

services:
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • references/compose-networking.md
  • references/container-security.md
  • references/docker-advanced.md
  • references/docker-compose-production.md
  • references/docker-fundamentals.md
  • references/docker-networking.md
  • references/docker-patterns-advanced.md
  • references/docker-patterns-fundamentals.md
  • references/docker-volume-storage.md
  • references/dockerfile-guide.md
  • references/image-optimization.md
  • references/merged-devops-docker.md
  • references/multi-stage-builds.md

FAQ

Что делает скилл docker-patterns?

Use when the user asks to write a Dockerfile, a multi-stage Dockerfile for a Node, Python or Go service, Docker Compose, .dockerignore, non-root containers, layer caching, BuildKit cache mounts, or image healthchecks. Produces small, secure Dockerfiles and Compose files. Not for container internals like cgroups (use docker-internals) or Kubernetes manifests (use cloud-native-kubernetes-patterns).

Как установить скилл docker-patterns?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл docker-patterns запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить docker-patterns с