Skip to content
docker-containerization logo

Stage 1: Build

docker-containerization

Load when using Docker for containerizing applications. Applies when creating Dockerfiles, docker-compose setups, multi-stage builds, or optimizing container images.

telum-ai/speck0installs2stars

SKILL.md

Full skill instructions

Multi-Stage Builds

Node.js Application

# Stage 1: Build
FROM node:20-alpine AS builder
WORKDIR /​app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Stage 2: Production
FROM node:20-alpine AS runner
WORKDIR /​app
ENV NODE_ENV=production

# Create non-root user
RUN addgroup --system --gid 1001 nodejs && \
    adduser --system --uid 1001 appuser

COPY --from=builder /​app/​dist ./​dist
COPY --from=builder /​app/​node_modules ./​node_modules
COPY --from=builder /​app/​package.json ./

USER appuser
EXPOSE 3000
CMD ["node", "dist/​index.js"]

Python Application

# Stage 1: Build
FROM python:3.12-slim AS builder
WORKDIR /​app
RUN pip install --no-cache-dir poetry
COPY pyproject.toml poetry.lock ./
RUN poetry export -f requirements.txt > requirements.txt
RUN pip wheel --no-cache-dir --wheel-dir /​wheels -r requirements.txt

# Stage 2: Production
FROM python:3.12-slim AS runner
WORKDIR /​app

RUN useradd --create-home appuser
COPY --from=builder /​wheels /​wheels
RUN pip install --no-cache /​wheels/​*

COPY . .
USER appuser
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0"]

Layer Caching

Optimize Build Order

# GOOD: Dependencies change less often than code
COPY package*.json ./
RUN npm ci                # Cached if package.json unchanged
COPY . .                   # Only this layer rebuilds on code change
RUN npm run build

# BAD: Code change invalidates npm install cache
COPY . .
RUN npm ci
RUN npm run build

Use .dockerignore

# .dockerignore
node_modules
npm-debug.log
dist
.git
.env
*.md
.DS_Store

Docker Compose

Development Stack

# docker-compose.yml
version: '3.8'

services:
  app:
    build: 
      context: .
      target: builder  # Use builder stage for dev
    volumes:
      - .:/​app
      - /​app/​node_modules  # Don't override node_modules
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgres://postgres:postgres@db:5432/​app
    depends_on:
      db:
        condition: service_healthy
    command: npm run dev

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: app
    volumes:
      - postgres_data:/​var/​lib/​postgresql/​data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/​data

volumes:
  postgres_data:
  redis_data:

Production Override

# docker-compose.prod.yml
version: '3.8'

services:
  app:
    build:
      target: runner  # Use production stage
    volumes: []       # No code mounting
    environment:
      - NODE_ENV=production
    restart: unless-stopped
# Development
docker-compose up

# Production
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Health Checks

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  CMD wget --no-verbose --tries=1 --spider http://localhost:3000/​health || exit 1
# docker-compose.yml
services:
  app:
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/​health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

Security Best Practices

Run as Non-Root

RUN addgroup --system --gid 1001 appgroup && \
    adduser --system --uid 1001 appuser

USER appuser

Read-Only Filesystem

services:
  app:
    read_only: true
    tmpfs:
      - /​tmp

Minimal Base Images

# Prefer
FROM node:20-alpine       # ~50MB
FROM python:3.12-slim     # ~120MB

# Avoid for production
FROM node:20              # ~1GB
FROM ubuntu:22.04         # ~70MB + your deps

Scan for Vulnerabilities

# Using Docker Scout
docker scout cves myimage:latest

# Using Trivy
trivy image myimage:latest

Common Patterns

Wait for Dependencies

services:
  app:
    depends_on:
      db:
        condition: service_healthy

Or use a script:

#!/​bin/​sh
# wait-for-db.sh
until pg_isready -h db -U postgres; do
  echo "Waiting for database..."
  sleep 2
done
exec "$@"

Environment Variables

services:
  app:
    environment:
      - DATABASE_URL=${DATABASE_URL}  # From .env file
    env_file:
      - .env.local

Secrets Management

services:
  app:
    secrets:
      - db_password

secrets:
  db_password:
    file: ./​secrets/​db_password.txt

Common Gotchas

PID 1 Signal Handling

Use exec form of CMD or use tini:

# GOOD: exec form receives signals properly
CMD ["node", "dist/​index.js"]

# Or use tini
RUN apk add --no-cache tini
ENTRYPOINT ["/​sbin/​tini", "--"]
CMD ["node", "dist/​index.js"]

node_modules in Volumes

Anonymous volume prevents host node_modules from overriding:

volumes:
  - .:/​app
  - /​app/​node_modules  # Anonymous volume

Build Context Size

Large contexts slow builds. Use .dockerignore.

Layer Order Matters

Less frequently changed files first → better cache utilization.


Quick Reference

TaskCommand/​Pattern
Builddocker build -t myapp .
Rundocker run -p 3000:3000 myapp
Compose updocker-compose up -d
View logsdocker-compose logs -f app
Shell accessdocker exec -it container_name sh
Clean updocker system prune -a
Multi-stageFROM base AS builder ... COPY --from=builder

References

More skills from telum-ai

project-brainstorm logo
telum-ai/speck

project-brainstorm

Load when a user has a vague idea, problem, or inspiration but isn't sure what to build. Use before /project-specify when the project concept needs crystallizing from loose thoughts into something concrete.

2 0
View
visual-quality logo
telum-ai/speck

visual-quality

Enforce visual design quality in every UI file. Fires for .tsx, .jsx, .vue, .svelte, and similar component files. Ensures implementations express the project's design personality rather than producing generic/boilerplate UI.

2 0
View
project-clarify logo
telum-ai/speck

project-clarify

Load after project.md exists to fill gaps through targeted Q&A. Use when project goals, target users, or scope feel underspecified. Run before project-context or project-architecture to prevent rework downstream.

2 0
View
story-outline logo
telum-ai/speck

story-outline

DEPRECATED in Speck v7. Use /speck-skeptical-review + /speck-decision-log instead — they replace outline-style research mapping with structured alternative enumeration and decision locking. /story-plan now performs just-in-time research inline. This skill remains for v6 compatibility but redirect...

2 0
View

Load when building offline-first applications that work without network connectivity. Applies when implementing local storage, sync queues, conflict resolution, or background sync.

2 0
View
project-constitution logo
telum-ai/speck

project-constitution

Load (Platform play level only) to define technical principles and architectural guardrails for the project. Produces constitution.md — optional but valuable when a team needs explicit coding standards, governance rules, or non-negotiable constraints. FIRST ACTION after loading: read template at ...

2 0
View
posthog-integration logo
telum-ai/speck

posthog-integration

Load when integrating PostHog for product analytics and feature flags. Applies when implementing event tracking, A/B testing, session replay, or funnel analysis.

2 0
View
project-validate logo
telum-ai/speck

project-validate

Load when all epics are validated and /audit has run for the project. Verifies the project meets its original vision and product-contract.md paid promise. Runs end-to-end JTBD smoke test via /larp across all personas. Declares a project-level readiness state. Produces project-validation-report.md...

2 0
View
story-scan logo
telum-ai/speck

story-scan

Load for brownfield stories where existing code must be understood before planning. Use when a story extends, modifies, or integrates with significant existing functionality. Produces codebase-scan.md — skip for fully greenfield stories. FIRST ACTION after loading: read template at .speck/templat...

2 0
View

Load when building serverless applications with AWS Lambda, Vercel Functions, or Cloudflare Workers. Applies when implementing FaaS patterns, managing cold starts, or optimizing serverless costs.

2 0
View
epic-scan logo
telum-ai/speck

epic-scan

Load for brownfield epics to analyze existing code patterns and implementations relevant to this epic's domain before planning. Use when the epic modifies or extends significant existing functionality. Skip for fully greenfield epics. FIRST ACTION after loading: read template at .speck/templates/...

2 0
View
epic-analyze logo
telum-ai/speck

epic-analyze

Load after epic-tech-spec.md and epic-breakdown.md exist — quality check for consistency and completeness before any story work begins. Catches spec drift and missing coverage between the tech spec and story breakdown. FIRST ACTION after loading: read template at .speck/templates/epic/epic-analys...

2 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View