AGENT SKILL

containerization

Write production-grade Dockerfiles, docker-compose, and Kubernetes manifests following security and reliability best practices. Triggers: Dockerfile, docker-compose, containerize, Docker image, Kubernetes, k8s manifest, container, pod, deployment yaml, multi-stage build, docker build, image size, container security.

License 许可
MIT
最近更新
2026-11-12
Stars
★ 1
Forks
1

01 前言 Front Matter

name
containerization
description
Write production-grade Dockerfiles, docker-compose, and Kubernetes manifests following security and reliability best practices. Triggers: Dockerfile, docker-compose, containerize, Docker image, Kubernetes, k8s manifest, container, pod, deployment yaml, multi-stage build, docker build, image size, container security.

02 资源文件 3

03 SKILL.md 正文

Containerization

Write production-quality container configurations — Dockerfiles, compose files, and Kubernetes manifests — that are secure, efficient, and reproducible.

Workflow: Dockerfile

Step 1: Understand the Application

Before writing a Dockerfile, establish:

  • Runtime: Node.js, Python, Go, Java, etc. and specific version
  • Build process: Does it need compilation, asset bundling, dependency installation?
  • Runtime dependencies: System packages, native libraries
  • Entry point: What command starts the application?
  • Configuration: Environment variables, config files, secrets

Step 2: Write the Dockerfile

Follow these principles in order of importance:

1. Use multi-stage builds — Separate build dependencies from the runtime image. Build artifacts in one stage, copy only what's needed to a slim final stage.

2. Pin base image versions — Never use latest. Use specific digests or version tags: node:20.11-alpine3.19, not node:latest.

3. Minimize layers and image size — Combine related RUN commands with &&. Use Alpine or distroless base images. Remove package manager caches after install.

4. Order for cache efficiency — Place infrequently changing instructions (system deps) before frequently changing ones (application code). Copy dependency manifests before source code.

5. Run as non-root — Create a dedicated user and switch to it. Never run production containers as root.

6. Use .dockerignore — Exclude node_modules, .git, .env, test files, docs from the build context.

Use templates/dockerfile.md as a starting point for Node.js, Python, Go, and docker-compose configurations.

Step 3: Validate

  • [ ] Image builds successfully
  • [ ] Image size is reasonable for the application type
  • [ ] Container runs as non-root user
  • [ ] No secrets baked into the image (check with docker history)
  • [ ] Health check is defined
  • [ ] .dockerignore excludes unnecessary files

Workflow: Docker Compose (Local Development)

Design compose files that give developers a one-command local environment:

  • All services defined (app, database, cache, queue)
  • Volumes for hot-reload development
  • Named volumes for data persistence across restarts
  • Environment variables with sensible defaults via .env.example
  • Health checks and dependency ordering (depends_on with condition: service_healthy)
  • Port mappings that avoid common conflicts

See references/dockerfile-patterns.md for compose patterns.

Workflow: Kubernetes Manifests

When creating K8s deployments:

  1. Define resource requests and limits — Always. Without them, a single pod can starve the cluster.
  2. Configure health probes — Liveness (is the process alive?), readiness (can it serve traffic?), startup (for slow-starting apps).
  3. Use ConfigMaps and Secrets — Never hardcode configuration in manifests.
  4. Set pod disruption budgets — For availability during upgrades.
  5. Use namespaces — Isolate environments (dev, staging, prod) and teams.
  6. Define HPA — Horizontal pod autoscaling based on CPU/memory or custom metrics.

When to Use Helm or Kustomize

For multi-environment deployments or when using a deployment repo pattern, plain manifests become hard to manage. Choose based on your needs:

  • Plain manifests: Single environment, few resources, no templating needed. Start here.
  • Kustomize: Multiple environments with small differences (replicas, resource limits, image tags). Uses patches over a base — no templating language to learn.
  • Helm: Complex deployments with many configurable parameters, or when you need to package charts for reuse. More powerful but more complexity.

See deployment-repo for organizing Helm charts and Kustomize overlays in a deployment repo, and gitops-delivery for using them with ArgoCD or Flux.

Principles Applied

  • KISS: Start with the simplest configuration that works. Single-stage Docker build before multi-stage. Docker Compose before Kubernetes.
  • DRY: Use build args and env vars to parameterize, not duplicate Dockerfiles per environment.
  • Security by default: Non-root, minimal image, no secrets in layers, read-only filesystem where possible.
  • YAGNI: Don't add Kubernetes if Docker Compose serves your scale. Don't add Helm charts if plain manifests suffice.

04 同仓库更多 Skills

SWEStash
SWEStash/swe-workflow-skills

writing-skills

Use when authoring, editing, or reviewing a skill in this library — a new SKILL.md, one that under-triggers, or hardening an existing one. Covers description and listing-budget rules, frontmatter, progressive disclosure, the 3-eval rule, and pressure-testing against rationalizations.

★ 1
SWEStash
SWEStash/swe-workflow-skills

working-agreement

Define and validate how a multi-session project is run — where plans, status and decisions live, session routines, new work, milestone close. README/CONTRIBUTING → project-documentation.

★ 1
SWEStash
SWEStash/swe-workflow-skills

verification-before-completion

Evidence gate before any claim that work is done, fixed, passing, or deployed. Route here when a message declares the work finished or asks to commit, push, merge, ship, or close it out, including a brief sign-off, and before git-workflow or release-management act on it. Writing the commit message or PR text itself → git-workflow.

★ 1
SWEStash
SWEStash/swe-workflow-skills

ui-ux-design

Design user experiences from an engineer's perspective — user flows, wireframes, interaction patterns, responsive strategy, navigation, loading/error/empty states. Triggers: design the UI, user flow, wireframe, how should this screen look, loading state, error state, empty state, responsive design, navigation, page layout, form design, mockup.

★ 1
SWEStash
SWEStash/swe-workflow-skills

threat-modeling

Design-time security analysis of a system or feature before it's built — trust boundaries, attack surface, STRIDE per element, abuse cases, prioritized mitigations that become security requirements. Triggers: threat model, STRIDE, trust boundary, attack surface, what could go wrong security-wise, security design review, abuse case, secure this design, security requirements. Reviewing EXISTING code/config for vulnerabilities → security-audit; use this skill while the design is still on the whiteboard.

★ 1
SWEStash
SWEStash/swe-workflow-skills

test-suite-design

Design comprehensive test suites for existing code — strategy across unit/integration/e2e, fixtures, factories, helpers. Triggers: add tests, write tests for, increase coverage, test this module, testing strategy, test plan, what tests do I need, test infrastructure, test helpers, this has no tests. Not for TDD — use tdd-workflow.

★ 1