IT 3300 : Virtualization

Docker — Compose

The problem

  • Real apps are several containers: web + database + cache
  • Running each by hand with the right flags is tedious and error-prone
  • Compose describes the whole app in one file

Compose v2

  • Use docker compose (a plugin), not the old docker-compose
  • The top-level version: key is obsolete — drop it
  • One compose.yaml (or docker-compose.yaml) per app

A Compose file

services:
  web:
    build: .
    ports:
      - "8080:5000"
    depends_on:
      - db
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - dbdata:/var/lib/postgresql/data

volumes:
  dbdata:

Reading the file

  • services — each container in the app
  • build vs image — build from a Dockerfile or pull an image
  • ports / environment / volumes — same ideas as the CLI flags
  • depends_on — start order

Everyday Compose

  • docker compose up -d — build/create/start everything
  • docker compose ps — status of the app's services
  • docker compose logs -f — tail all logs
  • docker compose down — stop and remove (add -v to drop volumes)

Networking for free

  • Compose creates a network for the app automatically
  • Services reach each other by service name (web -> db)
  • No manual docker network create needed

Why this matters going forward

  • Compose is declarative: you describe desired state, it reconciles
  • That's the same mental model as Kubernetes — just on one host
  • Compose is the natural stepping stone into orchestration

Lab goals

  • Convert your earlier multi-container app to a single Compose file
  • Bring the whole stack up and down with one command
  • Confirm data in the DB volume survives a down / up