docker-containers
Master Docker containerization, image building, optimization, and container registry management. Learn containerization best practices and image security.
What this skill does
# Docker & Containers
## Executive Summary
Production-grade container image building and management covering multi-stage builds, image optimization, security scanning, and registry operations. This skill provides deep expertise in creating minimal, secure, and efficient container images following industry best practices and OCI specifications.
## Core Competencies
### 1. Production-Grade Multi-Stage Builds
**Optimized Node.js Application**
```dockerfile
# Stage 1: Dependencies
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force
# Stage 2: Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Stage 3: Production
FROM gcr.io/distroless/nodejs20-debian12 AS production
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./
ENV NODE_ENV=production
USER nonroot:nonroot
EXPOSE 3000
CMD ["dist/server.js"]
```
**Optimized Go Application**
```dockerfile
# Stage 1: Build
FROM golang:1.22-alpine AS builder
RUN apk add --no-cache git ca-certificates tzdata
WORKDIR /app
# Cache dependencies
COPY go.mod go.sum ./
RUN go mod download && go mod verify
# Build
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s -X main.version=${VERSION}" \
-o /app/server ./cmd/server
# Stage 2: Production (scratch)
FROM scratch AS production
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /app/server /server
USER 65534:65534
EXPOSE 8080
ENTRYPOINT ["/server"]
```
**Optimized Python Application**
```dockerfile
# Stage 1: Dependencies
FROM python:3.12-slim AS builder
WORKDIR /app
RUN pip install --no-cache-dir poetry && \
poetry config virtualenvs.in-project true
COPY pyproject.toml poetry.lock ./
RUN poetry install --only main --no-interaction --no-ansi
# Stage 2: Production
FROM python:3.12-slim AS production
WORKDIR /app
# Create non-root user
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
# Copy virtual environment
COPY --from=builder /app/.venv /app/.venv
COPY . .
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
USER appuser:appgroup
EXPOSE 8000
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "app:app"]
```
### 2. Image Optimization Strategies
**Layer Optimization Checklist**
```
┌─────────────────────────────────────────────────────────────┐
│ IMAGE OPTIMIZATION CHECKLIST │
├─────────────────────────────────────────────────────────────┤
│ ✓ Use minimal base images (alpine, distroless, scratch) │
│ ✓ Multi-stage builds to exclude build tools │
│ ✓ Combine RUN commands to reduce layers │
│ ✓ Order layers by change frequency (least → most) │
│ ✓ Use .dockerignore to exclude unnecessary files │
│ ✓ Clean package manager cache in same RUN command │
│ ✓ Use specific version tags, avoid :latest │
│ ✓ Set appropriate user permissions │
│ ✓ Use COPY instead of ADD when possible │
│ ✓ Leverage build cache effectively │
└─────────────────────────────────────────────────────────────┘
```
**Optimized .dockerignore**
```
# Git
.git
.gitignore
# Dependencies
node_modules
.venv
vendor
# Build artifacts
dist
build
*.egg-info
# IDE and editors
.idea
.vscode
*.swp
*.swo
# Testing
coverage
.pytest_cache
__pycache__
# Documentation
docs
*.md
!README.md
# CI/CD
.github
.gitlab-ci.yml
Jenkinsfile
# Docker
Dockerfile*
docker-compose*
.docker
# Secrets and config
.env*
*.pem
*.key
secrets/
```
**Base Image Comparison**
```
┌──────────────────┬────────────┬─────────────────────────────────┐
│ Base Image │ Size │ Use Case │
├──────────────────┼────────────┼─────────────────────────────────┤
│ ubuntu:22.04 │ ~77MB │ Debugging, full tooling │
│ debian:slim │ ~52MB │ Compatibility, some tools │
│ alpine:3.19 │ ~7MB │ Small size, musl libc │
│ distroless │ ~2-20MB │ Minimal, no shell │
│ scratch │ 0MB │ Static binaries only │
│ chainguard │ ~2-10MB │ Security-focused, maintained │
└──────────────────┴────────────┴─────────────────────────────────┘
```
### 3. Container Security
**Security-Hardened Dockerfile**
```dockerfile
FROM node:20-alpine AS builder
# ... build steps ...
FROM gcr.io/distroless/nodejs20-debian12
# Use digest for immutability
# FROM gcr.io/distroless/nodejs20-debian12@sha256:abc123...
WORKDIR /app
# Copy only necessary files
COPY --from=builder --chown=nonroot:nonroot /app/dist ./dist
COPY --from=builder --chown=nonroot:nonroot /app/node_modules ./node_modules
COPY --from=builder --chown=nonroot:nonroot /app/package.json ./
# Security labels
LABEL org.opencontainers.image.source="https://github.com/org/repo"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.vendor="MyCompany"
# Run as non-root
USER nonroot:nonroot
# Read-only filesystem compatible
VOLUME ["/tmp"]
ENV NODE_ENV=production
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["/nodejs/bin/node", "-e", "require('http').get('http://localhost:3000/health')"]
ENTRYPOINT ["/nodejs/bin/node"]
CMD ["dist/server.js"]
```
**Image Scanning with Trivy**
```bash
# Scan image for vulnerabilities
trivy image --severity HIGH,CRITICAL myapp:latest
# Scan with SARIF output for GitHub
trivy image --format sarif --output results.sarif myapp:latest
# Scan and fail on critical
trivy image --exit-code 1 --severity CRITICAL myapp:latest
# Generate SBOM
trivy image --format cyclonedx --output sbom.json myapp:latest
```
**Image Signing with Cosign**
```bash
# Generate key pair
cosign generate-key-pair
# Sign image
cosign sign --key cosign.key myregistry.io/myapp:v1.0.0
# Verify signature
cosign verify --key cosign.pub myregistry.io/myapp:v1.0.0
# Keyless signing (GitHub Actions)
cosign sign --yes \
--oidc-issuer=https://token.actions.githubusercontent.com \
myregistry.io/myapp:${{ github.sha }}
```
### 4. Registry Management
**Multi-Registry Push Configuration**
```bash
# Build with BuildKit
DOCKER_BUILDKIT=1 docker build \
--platform linux/amd64,linux/arm64 \
--push \
--cache-from type=registry,ref=myregistry.io/myapp:cache \
--cache-to type=registry,ref=myregistry.io/myapp:cache,mode=max \
-t myregistry.io/myapp:v1.0.0 \
-t myregistry.io/myapp:latest \
.
# Push to multiple registries
for registry in docker.io gcr.io ghcr.io; do
docker tag myapp:v1.0.0 $registry/myorg/myapp:v1.0.0
docker push $registry/myorg/myapp:v1.0.0
done
```
**Registry Authentication in Kubernetes**
```yaml
# ImagePullSecret for private registry
apiVersion: v1
kind: Secret
metadata:
name: regcred
namespace: production
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: |
eyJhdXRocyI6eyJteXJlZ2lzdHJ5LmF6dXJlY3IuaW8iOnsiYXV0aCI6IlkyeH...
---
# Usage in Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
template:
spec:
imagePullSecrets:
- name: regcred
containers:
- name: app
image: myregistry.azurecr.io/myapp:v1.0.0@sha256:abc123...
```
### 5. Build Optimization
**BuildKit Caching Strategies**
```dockerfile
# syntax=docker/dockerfile:1.6
FROM node:20-alpine AS builder
# Mount cache for npm
RUN --mount=type=cache,target=/root/.npm \
npm ci
# Mount secrets without embedding in image
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc \
npm install @private/package
# Mount ssh for private repos
RUN --mount=type=ssh \
git clone [email protected]:org/private-repo.git
```
**GitHub Actions CI/CD**
```yaml
name: Build and Push
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.