DEV Community

Alex Spinov
Alex Spinov

Posted on

Docker Compose Has Free Multi-Container Orchestration — Run Your Full Stack Locally

The Local Development Problem

Your app needs PostgreSQL, Redis, and Elasticsearch. You could install all three on your machine. Or use a cloud service for each. Or fight with Homebrew versions.

Or you could define your entire stack in one file and start everything with one command.

Docker Compose: Your Full Stack in One File

Docker Compose defines and runs multi-container applications. One YAML file, one command, everything running.

Define Your Stack

# docker-compose.yml
services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgres://postgres:password@db:5432/myapp
      - REDIS_URL=redis://redis:6379
    depends_on:
      - db
      - redis

  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: password
      POSTGRES_DB: myapp
    volumes:
      - pgdata:/var/lib/postgresql/data

  redis:
    image: redis:7-alpine

volumes:
  pgdata:
Enter fullscreen mode Exit fullscreen mode

One Command

docker compose up
Enter fullscreen mode Exit fullscreen mode

PostgreSQL, Redis, and your app — all running. All connected. Stop with Ctrl+C.

Why Every Developer Should Know Compose

1. Reproducible Environments

"Works on my machine" is dead. The docker-compose.yml IS the machine.

2. New Team Member Onboarding

git clone repo
docker compose up
# Done. Full dev environment in 2 minutes.
Enter fullscreen mode Exit fullscreen mode

No 15-page setup guide. No "install PostgreSQL 16, then configure pg_hba.conf, then..."

3. Production-Like Development

Your local environment matches production. Same database version, same Redis version, same configuration.

Advanced Patterns

Hot Reload for Development

services:
  app:
    build: .
    volumes:
      - ./src:/app/src  # Code changes reflect instantly
    command: npm run dev
Enter fullscreen mode Exit fullscreen mode

Health Checks

services:
  db:
    image: postgres:16
    healthcheck:
      test: pg_isready -U postgres
      interval: 5s
      retries: 5

  app:
    depends_on:
      db:
        condition: service_healthy
Enter fullscreen mode Exit fullscreen mode

Multiple Environments

# Development
docker compose up

# Testing
docker compose -f docker-compose.yml -f docker-compose.test.yml up

# Production
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
Enter fullscreen mode Exit fullscreen mode

Compose Watch (New in v2)

services:
  app:
    develop:
      watch:
        - action: sync
          path: ./src
          target: /app/src
        - action: rebuild
          path: package.json
Enter fullscreen mode Exit fullscreen mode
docker compose watch
Enter fullscreen mode Exit fullscreen mode

File changes sync to the container. Package.json changes trigger rebuild. Like nodemon but for containers.

Common Stacks

Next.js + PostgreSQL + Redis
Django + PostgreSQL + Celery + RabbitMQ
Rails + PostgreSQL + Sidekiq + Redis
Express + MongoDB + Redis

All definable in one file. All running with one command.

Get Started

Docker Compose is included with Docker Desktop. If you have Docker, you have Compose.

docker compose version
Enter fullscreen mode Exit fullscreen mode

Dockerize your data pipelines. 88+ scrapers on Apify. Custom: spinov001@gmail.com

Top comments (0)