Skip to main content...
Docker
20 min

Day 35: Docker Compose for multi-service dev

Compose: describing your whole stack declaratively

Instead of typing out docker run commands with networks and volumes by hand, docker-compose.yml describes every service, its image/build context, ports, volumes, and dependencies — then docker compose up builds/starts everything together, on one auto-created network.

A real multi-service example (this course's own stack)
services:
  api:
    build: ./api
    ports:
      - '3000:3000'
    environment:
      - DB_HOST=db
      - REDIS_HOST=redis
    depends_on:
      - db
      - redis

  db:
    image: postgres:16
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=devpassword

  redis:
    image: redis:7

volumes:
  pgdata:

"depends_on" only waits for the container to start, not to be ready

Postgres's container can be running before Postgres itself is actually accepting connections. Real apps add a retry loop or a healthcheck (healthcheck: in Compose) rather than assuming depends_on guarantees readiness.

Key terms

docker-compose.yml
A declarative file describing a multi-container application's services, networking, and volumes.

Your API container crashes on startup because Postgres "isn't ready yet" even though depends_on lists it. What's the real fix?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 35: Docker Compose for multi-service dev | RBTechIconX