Cheat SheetsDockerOrchestration

Orchestration — Cheat Sheet

Docker · 2 topics. Download the PDF or the Instagram carousel and share it.

Cheat Sheet · AiCanCode.org
Orchestration
Docker2 topicsQuick revision reference
1

Docker Compose — Multi-Container Apps

Docker Compose defines and runs multi-container applications with a single YAML file — replacing dozens of docker run commands with `docker compose up`.

  • Compose defines multi-container apps declaratively in a single YAML file.
  • All services in a Compose file share a default network and resolve each other by service name.
  • depends_on with condition: service_healthy waits for healthchecks before starting dependent services.
  • docker-compose.override.yml is auto-merged and is the standard pattern for dev overrides.
  • Use .env files for secrets and environment-specific values — never hardcode passwords.
  • docker compose down -v deletes volumes — use with caution, it wipes database data.
docker-compose.yml — full-stack app
# docker-compose.yml

version: '3.9'



services:

  # ── Database ────────────────────────────────────────

  postgres:

    image: postgres:16-alpine

    environment:

      POSTGRES_DB: myapp

      POSTGRES_USER: user

      POSTGRES_PASSWORD: secret

    volumes:

      - postgres-data:/var/lib/postgresql/data

    healthcheck:

      test: ["CMD-SHELL", "pg_isready -U user -d myapp"]

      interval: 10s

      timeout: 5s

      retries: 5



  # ── Cache ────────────────────────────────────────────

  redis:

    image: redis:7-alpine

    command: redis-server --maxmemory 256mb --maxmemory-policy allkeys-lru

    volumes:

      - redis-data:/data



  # ── API Backend ──────────────────────────────────────

  api:

    build:

      context: ./backend

      dockerfile: Dockerfile

    environment:

      DATABASE_URL: postgres://user:secret@postgres:5432/myapp

      REDIS_URL: redis://redis:6379

    ports:

      - "8000:8000"

    depends_on:

      postgres:

        condition: service_healthy   # wait for DB healthcheck to pass

      redis:

        condition: service_started

    restart: unless-stopped



  # ── Frontend ─────────────────────────────────────────

  frontend:

    build: ./frontend

    environment:

      NEXT_PUBLIC_API_URL: http://localhost:8000

    ports:

      - "3000:3000"

    depends_on:

      - api



volumes:

  postgres-data:

  redis-data:
2

From Docker to Kubernetes

Docker runs containers on a single host. Kubernetes orchestrates containers across a cluster of hosts, providing auto-scaling, self-healing, rolling deployments, and service discovery at scale.

  • Kubernetes orchestrates containers across a cluster; Docker runs containers on a single host.
  • Pod is the smallest K8s unit — usually one container. Deployment manages replicas and rolling updates.
  • Service provides stable DNS and load balancing for a set of pods selected by label.
  • readinessProbe controls when traffic is sent to a pod; livenessProbe triggers pod restart.
  • Use managed Kubernetes (EKS, GKE, AKS) in production to avoid managing the control plane.
  • Start with Docker Compose for development; migrate to Kubernetes when you need multi-host orchestration and auto-scaling.
Docker Compose → Kubernetes mapping
Compose                   →   Kubernetes

─────────────────────────────────────────────────────

docker-compose.yml        →   collection of YAML manifests

service (with image)      →   Pod template in a Deployment

replicas: 3               →   replicas: 3 in Deployment

ports: "3000:3000"        →   Service (ClusterIP/NodePort/LoadBalancer)

volumes: named            →   PersistentVolumeClaim (PVC)

environment: vars         →   env in container spec

depends_on                →   initContainers or readiness probes

healthcheck               →   livenessProbe + readinessProbe

restart: always           →   restartPolicy: Always (default)

networks                  →   Kubernetes networking (pods talk by service name)



# Convert Compose to K8s with Kompose:

kompose convert -f docker-compose.yml

# Generates: deployment.yaml, service.yaml, persistentvolumeclaim.yaml
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/docker