It's Monday morning and you've joined a new project. The README says "just run it locally." Two hours later you're still installing a specific MySQL version, a Redis server, and a PHP extension that refuses to compile. Meanwhile your teammate says, "Weird, it works on mine."

This is the problem Docker Compose was built to kill. Instead of a wiki page of install steps, you describe your whole stack in one small file, and a single command brings it up the same way on every machine.

A good dev environment is one you can delete and rebuild in a minute without feeling anything.

What Compose Actually Does

Docker runs one container at a time. Real applications rarely need just one: a web app, a database, a cache, maybe a mail catcher. Compose lets you declare all of them together in a file called compose.yaml and manage them as a unit.

Think of it as a recipe card for your stack. Each service is an ingredient, and Compose handles the cooking order, the shared network, and the cleanup. Modern Docker ships Compose as a plugin, so the command is docker compose (with a space), not the old standalone docker-compose.

One small modern detail: the top-level version: line you see in older tutorials is obsolete. Current Compose ignores it and may print a warning, so you can simply leave it out.

A Realistic First File

Here is a minimal stack: a Python web app and a PostgreSQL database. The values are samples only.

services:
  web:
    build: .
    ports:
      - "8000:8000"
    environment:
      DATABASE_URL: postgres://app:devpass@db:5432/appdb
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:16
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: devpass
      POSTGRES_DB: appdb
    volumes:
      - dbdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app -d appdb"]
      interval: 5s
      timeout: 3s
      retries: 10

volumes:
  dbdata:

Run docker compose up -d and both containers start. Notice the connection string uses db as the hostname. Compose creates a private network where every service is reachable by its service name, so you never hunt for IP addresses.

Three Ideas That Do the Heavy Lifting

Ports connect the container to your machine. "8000:8000" means "host port 8000 forwards to container port 8000." Only publish what you actually need to reach from your browser; the database above is deliberately not published, so only web can talk to it.

Volumes are how data survives. Containers are disposable, so without a volume your database vanishes when the container is removed. The named volume dbdata lives outside the container and keeps your tables safe across rebuilds.

Healthchecks with depends_on solve the classic race condition. Plain depends_on only waits until a container has started, not until the database is ready to accept connections. Adding condition: service_healthy makes web wait for the healthcheck to pass. That one line removes a whole category of "connection refused on first boot" errors.

The Daily Commands

You'll use a handful of commands for 95% of your work:

CommandWhat it does
docker compose up -dStart everything in the background
docker compose logs -f webFollow one service's logs
docker compose exec db psql -U app appdbOpen a shell or client inside a running service
docker compose up -d --buildRebuild images after changing code or the Dockerfile
docker compose downStop and remove containers and the network (keeps volumes)
docker compose down -vSame, but also deletes volumes (your data)

That last pair deserves respect. down is safe; down -v is the "nuke it from orbit" button. It's wonderful for a fresh start and terrible if you forgot your only copy of test data lives there.

Keep Secrets Out of the File

Hard-coding devpass is fine for a throwaway local database, but the habit spreads. Move values into a .env file next to compose.yaml, which Compose reads automatically:

# .env  (add this file to .gitignore)
DB_PASSWORD=change-me-locally
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}

Commit a .env.example with fake values so teammates know what to fill in. Real credentials should never land in version control, and a compose file is exactly the kind of file that gets copied around.

Mistakes Worth Avoiding Early

Using localhost inside a container is the most common one. Inside the web container, localhost means that container itself, not your laptop and not the database. Use the service name instead.

Another is relying on latest image tags. Pin versions such as postgres:16 so a surprise upgrade doesn't break your environment on a random Tuesday. Finally, don't treat this dev setup as a production deployment. Compose is superb for local work and small single-host setups, but production usually needs proper secrets handling, backups, and monitoring.

The Short Version

Compose turns "follow these 14 steps" into docker compose up. Declare services in compose.yaml, let service names act as hostnames, store data in named volumes, gate startup with healthchecks, and keep secrets in .env. Skip the obsolete version: line and pin your image tags.

Spend an afternoon writing that first file for your own project. The next time someone joins your team, their "first day setup" will be one command and a cup of coffee, and that's a small kindness worth building.