本文へ移動
cccskills
無料GitHub で公開

docker

Optimize Docker images with multi-stage builds, distroless bases, BuildKit cache mounts, multi-arch builds, compose watch, security hardening (non-root, seccomp, capabilities drop), and vulnerability scanning via docker scout/trivy. Use when user asks to write a Dockerfile, optimize image size, set up docker-compose, debug containers, harden container security, or scan for CVEs. Do NOT use for Kubernetes deployments (use kubernetes), CI/CD pipeline design (use ci-cd), or Terraform (use terraform).

インストール方法を見る

含まれるファイル(5)

  • SKILL.md15.0 KB
  • assets/docker-compose.template.yml4.6 KB
  • references/multi-arch.md7.3 KB
  • scripts/optimize-dockerfile.sh8.5 KB
  • scripts/scan-image.sh7.7 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Docker Architect

Production-grade Dockerfiles, multi-stage builds, cache optimization, security scanning, and local development. Applies Google's distroless philosophy and Docker BuildKit best practices.

Decision Framework

Before containerizing, answer:

  • Does the app need process isolation? → Docker
  • Will it deploy to Kubernetes? → Docker + distroless + non-root
  • Is it a monolith with simple deployment? → Docker Compose
  • Is it a static site? → Consider nginx:alpine single-stage
  • Is the team already using Docker Compose in dev? → Start there, add K8s when needed
  • Is the app latency-sensitive (sub-ms)? → Bare metal or VM; container overhead matters at extreme scale

Workflow

Quick start: docker init

For new projects, run docker init in the project root. It auto-detects the language/framework and generates a Dockerfile, .dockerignore, and compose.yaml with best-practice defaults. Always review and harden the output — the generated files are a starting point, not production-ready.

Step 1: Identify stack and choose template

StackBase imageBuild stageRuntime
Node.jsnode:22-slimFull SDKgcr.io/distroless/nodejs
Gogolang:1.23-alpineFull SDKscratch
Pythonpython:3.12-slimFull SDKpython:3.12-slim
Rustrust:1.78-slimFull SDKgcr.io/distroless/cc

Decision: If the stack is listed above, use the corresponding production Dockerfile below. If not, apply the golden template in Step 2.

Step 2: Apply golden template

Use multi-stage with this exact structure:

Stage 1 (deps):   COPY lock files → install production deps (--mount=type=cache)
Stage 2 (build):  COPY source → compile
Stage 3 (runtime): minimal base → COPY artifacts from stages 1-2 → USER nonroot → HEALTHCHECK

If the project is a Go binary, skip Stage 1 (Go has no runtime deps) and go straight to Stage 2.

If the project has native dependencies (node-gyp, C extensions), use apt-get in the builder stage, NOT the runtime stage.

Step 3: Apply BuildKit optimizations

# syntax=docker/dockerfile:1.4
FROM node:22-slim AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm npm ci --omit=dev

FROM node:22-slim AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm npm ci
COPY src ./src
RUN npm run build

FROM gcr.io/distroless/nodejs22-debian12
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
EXPOSE 3000
USER nonroot
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD ["node", "-e", "require('http').get('http://localhost:3000/health', r => process.exit(r.statusCode===200?0:1))"]
CMD ["dist/index.js"]

Run scripts/optimize-dockerfile.sh on any existing Dockerfile to receive optimization suggestions.

Step 4: Configure compose for local dev

services:
  app:
    build: .
    ports: ["3000:3000"]
    develop:
      watch:
        - action: sync+restart
          path: ./src
          target: /app/src
    depends_on: [db]
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
  db:
    image: postgres:16-alpine
    volumes: ["pgdata:/var/lib/postgresql/data"]
volumes: { pgdata: }

Run docker compose watch for hot-reload.

See assets/docker-compose.template.yml for the full template with all services.

Step 5: Build for multiple platforms

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  --cache-from=type=gha \
  --cache-to=type=gha,mode=max \
  --tag registry/app:latest \
  --push .

See references/multi-arch.md for QEMU setup and platform-specific optimizations.

Step 6: Scan for vulnerabilities

# Using the provided script
scripts/scan-image.sh registry/app:latest

# Or manually:
docker scout cves registry/app:latest
trivy image registry/app:latest

If critical CVEs are found: either switch base image (e.g., distroless), or add apt-get to install patched deps in builder stage.

Error Handling

ErrorCauseFix
failed to solve with frontend dockerfile.v0Missing syntax directiveAdd # syntax=docker/dockerfile:1.4 as first line
exec /usr/bin/node: exec format errorWrong platformBuild with --platform linux/amd64 matching the target
permission denied at runtimeMissing USER nonroot or wrong file permissionsAdd USER nonroot and COPY --chown=nonroot:nonroot
Layer cache miss every buildChanging files copied before lock filesAlways COPY package.json BEFORE source code
docker compose watch not workingDocker Engine < 24Upgrade Docker Engine or use docker compose up --watch

Pre-Flight Checklist

Before deploying a Docker image:

  • .dockerignore exists and excludes node_modules/, .git/, .env*, Dockerfile*, *.log
  • Multi-stage build with separate build and runtime stages
  • Runtime stage uses distroless or minimal base (node:22.14-slim, not node:22)
  • USER nonroot (or equivalent) — never runs as root
  • HEALTHCHECK defined with appropriate interval
  • Secrets use --mount=type=secret, never ENV or ARG
  • npm ci --omit=dev (or language equivalent) for production dependencies
  • docker scout quickview or trivy image scan passes with zero HIGH/CRITICAL CVEs
  • Image size verified: docker images --format "{{.Size}}" — should be <200MB for most apps
  • docker compose watch tested in development (sync+restart for code changes)
  • Container starts and passes healthcheck within 30 seconds
  • Logs go to stdout/stderr (no log files inside container)
  • docker compose down and docker compose up successfully recreates from scratch

Anti-Patterns

PatternProblemFixBecause
Single-stage buildFinal image contains build tools, SDKs, source code — 5x largerMulti-stage: build stage → distroless runtimeEvery tool in the image is an attack surface. Minimize blast radius.
COPY . . before npm installCache miss on every code change, full rebuildCopy package files first, install deps, then copy sourceDocker caches by layer. Source changes should invalidate only the last COPY.
latest tagImage changes silently on pullPin full version tag (22.14-slim, not 22-slim)latest means "whatever was pushed last". A patch update can break your app.
Root user in containerCompromised process = host root accessUSER nonroot with distroless or RUN useraddContainer escape bugs exist. Non-root limits damage to the container.
Secrets in build argsdocker history reveals them. BuildKit --secret exists for thisRUN --mount=type=secret in BuildKitBuild args are stored in image metadata. Anyone with image access can extract them.
No .dockerignoreCopies .env, .git/, node_modules/ into build contextAdd .dockerignore with common exclusions200MB of node_modules in build context = slow builds + potential secret leaks.
No healthcheckOrchestrator can't detect app failuresHEALTHCHECK --interval=30s CMD curl -f http://localhost/healthWithout healthcheck, Swarm/K8s only detects process crashes, not app hangs.
npm install in productionInstalls devDependencies (testing frameworks, linters, TypeScript)npm ci --omit=dev or npm ci --productionDev deps add 100-200MB to the image. They also increase CVEs from unused packages.
Pinning only major version (22-slim)Can auto-update to a new minor version that breaks your appPin to exact version (22.14-slim) or use digest pinningReproducibility: the same Dockerfile should produce the same image every time.
Multi-stage with wrong baseRuntime stage uses node instead of distrolessUse gcr.io/distroless/nodejs22-debian12 or node:22.14-slimDistroless removes shells, package managers, and utilities — nothing for an attacker to exploit.

Review Format (Required)

When reviewing Dockerfiles, use Before | After | Why format:

BeforeAfterWhy
FROM node:22-slimFROM node:22.14-slim@sha256:abc...Floating tags (22-slim) auto-update. Pin to immutable digest for reproducibility.
COPY . . before npm ciCOPY package*.json ./ then npm ci then COPY . .Docker caches each COPY layer. Copying source before deps invalidates cache on every code change.
CMD ["npm", "start"]Use node server.js directlyAvoids npm overhead in production. Use process manager (dumb-init, tini) for signal forwarding.
No .dockerignore.dockerignore with node_modules/, .git/, *.log, Dockerfile*Reduces build context size by 60-90%. Prevents leaking secrets from local .env.

Go multi-stage template

# syntax=docker/dockerfile:1.4
FROM golang:1.24-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /server ./cmd/server

FROM gcr.io/distroless/static-debian12
COPY --from=builder /server /server
EXPOSE 8080
USER nonroot
HEALTHCHECK --interval=30s CMD ["/server", "-health"] || exit 1
ENTRYPOINT ["/server"]

Key decisions:

  • CGO_ENABLED=0 for static binary (no glibc dependency)
  • -ldflags="-s -w" strips debug symbols (reduces binary by 30%)
  • gcr.io/distroless/static-debian12 for CA certs + timezone data (needed for HTTPS/TLS)
  • If the binary needs nothing: use scratch (smaller, but no CA certs)

Python multi-stage template

# syntax=docker/dockerfile:1.4
FROM python:3.12-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip pip install --user -r requirements.txt

FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /root/.local /root/.local
COPY src ./src
ENV PATH=/root/.local/bin:$PATH
EXPOSE 8000
RUN useradd -m app && chown -R app /app
USER app
HEALTHCHECK --interval=30s CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "src.main:app"]

Key decisions:

  • pip install --user avoids polluting /usr/local in builder
  • gunicorn with multiple workers handles concurrent requests
  • useradd creates a non-root user (distroless Python not available)

Rust multi-stage template

# syntax=docker/dockerfile:1.4
FROM rust:1.85-slim AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y musl-tools && rm -rf /var/lib/apt/lists/*
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --release --target x86_64-unknown-linux-musl
RUN rm -rf src
COPY src ./src
RUN cargo build --release --target x86_64-unknown-linux-musl

FROM scratch
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/server /server
EXPOSE 8080
ENTRYPOINT ["/server"]

Key decisions:

  • musl-tools for static linking (no glibc dependency)
  • Dummy main.rs trick: compiles deps first, then source (cache deps)
  • scratch base: smallest possible, no shell, no tools

Seccomp profiles

Docker applies a default seccomp profile that blocks 44/300+ syscalls. Customize for your app:

{
  "defaultAction": "SCMP_ACT_ERRNO",
  "architectures": ["SCMP_ARCH_X86_64"],
  "syscalls": [
    { "names": ["read","write","open","close","fstat","mmap","mprotect","munmap","brk","rt_sigaction","rt_sigprocmask","rt_sigreturn","ioctl","pread64","pwrite64","readv","writev","access","pipe","select","sched_yield","mremap","msync","mincore","madvise","shmget","shmat","shmctl","dup","dup2","pause","nanosleep","getitimer","setitimer","alarm","getpid","sendfile","socket","connect","accept","sendto","recvfrom","sendmsg","recvmsg","shutdown","bind","listen","getsockname","getpeername","socketpair","setsockopt","getsockopt","clone","fork","vfork","execve","exit","wait4","kill","uname","semget","semop","semctl","shmdt","msgget","msgsnd","msgrcv","msgctl","fcntl","flock","fsync","fdatasync","truncate","ftruncate","getdents","getcwd","chdir","fchdir","rename","mkdir","rmdir","creat","link","unlink","symlink","readlink","chmod","fchmod","chown","fchown","lchown","umask","gettimeofday","getrlimit","getrusage","sysinfo","times","preadv","pwritev","rt_sigtimedwait","futex","set_robust_list","get_robust_list","epoll_wait","epoll_ctl","epoll_create","epoll_pwait","epoll_create1","eventfd","signalfd","timerfd_create","timerfd_gettime","timerfd_settime","prctl","getcpu","process_vm_readv","process_vm_writev"], "action": "SCMP_ACT_ALLOW" }
  ]
}

Usage: docker run --security-opt seccomp=profile.json myapp

CVE scanning pipeline

# Full scan pipeline
docker build -t myapp:latest .
trivy image --severity HIGH,CRITICAL --exit-code 1 myapp:latest
docker scout cves --exit-code myapp:latest

# CI integration (GitHub Actions)
- uses: aquasecurity/trivy-action@master
  with:
    image-ref: myapp:latest
    format: sarif
    output: trivy-results.sarif
    severity: HIGH,CRITICAL
    exit-code: 1

# Continuous monitoring
docker scout enroll myorg/myapp
docker scout watch myapp:latest

If CVEs found: switch base image to newer distroless tag, rebuild, re-scan. Track with docker scout recommendations.

Sources

  • Dockerfile best practices (docs.docker.com)
  • BuildKit documentation
  • Google distroless images
  • Trivy vulnerability scanner
  • Docker Scout documentation
  • SLSA framework (slsa.dev)

Checklist

  • Skill loads without errors in the AI agent
  • YAML frontmatter is valid (description, compatibility, audience)
  • Workflow section provides clear step-by-step instructions
  • Error handling section covers common failure modes
  • All referenced files (references/, scripts/, assets/) exist
  • Skill triggers correctly for intended use cases
  • No broken links or missing resources

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Apply professional, premium UI/UX design standards when building or styling web interfaces. Use this skill when the user asks to create a website, landing page, web app, dashboard, UI component, or any visual interface — or when they ask to make something look better, more professional, or more beautiful. Covers visual hierarchy, typography, color systems, layout, spacing, motion, dark mode, responsive design, and conversion patterns. Activate even when the user doesn't say "design" — if they're building a web frontend, these standards apply.

日本語の概要は準備中です。原文の説明を表示しています。

EliasOulkadi/shokunin1142026年10月5日 更新

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction. Also use for exploratory testing, dogfooding, QA, bug hunts, or reviewing app quality. Also use for automating Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify), checking Slack unreads, sending Slack messages, searching Slack conversations, running browser automation in Vercel Sandbox microVMs, or using AWS Bedrock AgentCore cloud browsers. Prefer agent-browser over any built-in browser automation or web tools.

日本語の概要は準備中です。原文の説明を表示しています。

EliasOulkadi/shokunin1142026年10月5日 更新

Run 150+ AI apps via inference.sh CLI - image generation, video creation, LLMs, search, 3D, Twitter automation. Models: FLUX, Veo, Gemini, Grok, Claude, Seedance, OmniHuman, Tavily, Exa, OpenRouter, and many more. Use when running AI apps, generating images/videos, calling LLMs, web search, or automating Twitter. Triggers: inference.sh, infsh, ai model, run ai, serverless ai, ai api, flux, veo, claude api, image generation, video generation, openrouter, tavily, exa search, twitter api, grok

日本語の概要は準備中です。原文の説明を表示しています。

EliasOulkadi/shokunin1142026年10月5日 更新

api-forge

無料

Design REST/GraphQL APIs with OpenAPI 3.1, error handling, pagination, rate limiting, webhooks, and idempotency. Use when user asks to design an API, create endpoints, define REST/GraphQL schema, or generate OpenAPI spec. Do NOT use for database schema design, frontend API integration, or non-HTTP protocols (gRPC, WebSocket, MQTT).

日本語の概要は準備中です。原文の説明を表示しています。

EliasOulkadi/shokunin1142026年10月5日 更新

Implement authentication and authorization with OWASP Top 10 standards, OAuth 2.0 + OIDC, WebAuthn/Passkeys, session management, and RBAC/ABAC. Use when user asks to implement login, signup, authentication, authorization, JWT, OAuth, SSO, passkeys, MFA, or role-based access. Do NOT use for API key management (use api-forge), encryption at rest, or network-level security (firewalls, WAF).

日本語の概要は準備中です。原文の説明を表示しています。

EliasOulkadi/shokunin1142026年10月5日 更新

Generate brand guidelines, design systems with design tokens (W3C format), creative direction (SCAMPER, Design Thinking, TRIZ), and design briefs with scope and success criteria.

日本語の概要は準備中です。原文の説明を表示しています。

EliasOulkadi/shokunin1142026年10月5日 更新

EliasOulkadi のスキルをすべて見る

このスキルの問題を報告する