Back to devops
devops#docker#docker-compose#devops-basics

Docker Compose: Run Many Containers Together

How to describe a small stack (app + database + cache) in one YAML file and start it all with a single command.

Jane Contributor August 2, 2026 1 views

Docker Compose

Real apps are rarely just one container. You usually need:

  • your app,
  • a database,
  • maybe a cache (Redis),
  • maybe a queue.

Docker Compose lets you describe all of them in one docker-compose.yml file and start them together.

A tiny working example

services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/app
    depends_on:
      - db

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: app
    volumes:
      - db-data:/var/lib/postgresql/data

volumes:
  db-data:

Two commands to remember

docker compose up -d      # start everything in the background
docker compose down       # stop and remove everything

Beginner tips

  • Service names become hostnames: from web, connect to the DB using db:5432 — not localhost.
  • volumes keep your database data safe across restarts.
  • depends_on starts services in order (but does not wait for them to be ready; use a healthcheck for that).

Real-world example

For a college project you can spin up a Node.js app, a Postgres database and a Redis cache with one command, then wipe everything with one command — perfect for demos and testing.

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.