Skip to main content
🎤 Luca Berton is speaking at Red Hat Summit & KubeCon EU 2026!Learn more →
Back to Blog

Docker Compose for Dev Environments

Set up reproducible local development environments with Docker Compose. Multi-service stacks, hot reload, database seeding, and team workflows.

Luca BertonApril 9, 20261 min read

Why Docker Compose for Dev?

Every developer on the team runs the exact same stack: same database version, same Redis, same message queue. No more "works on my machine."

Full-Stack Example

A Node.js API with PostgreSQL and Redis:

yaml
version: "3.8"
services:
  api:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://app:secret@db:5432/myapp
      - REDIS_URL=redis://cache:6379
    volumes:
      - ./src:/app/src
    depends_on:
      db:
        condition: service_healthy
      cache:
        condition: service_started

  db:
    image: postgres:16
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: myapp
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app"]
      interval: 5s
      timeout: 5s
      retries: 5

  cache:
    image: redis:7-alpine
    ports:
      - "6379:6379"

volumes:
  pgdata:
Related Course

Master this topic with hands-on labs

Go beyond reading — build real projects in sandboxed environments with expert video guidance.

Browse Courses →

Hot Reload

Mount your source code as a volume so changes reflect instantly:

yaml
services:
  api:
    build: .
    volumes:
      - ./src:/app/src
      - /app/node_modules  # Prevent overwriting container's node_modules
    command: npm run dev

The /app/node_modules anonymous volume keeps the container's installed packages separate from your host.

Database Seeding

Place SQL files in the init directory:

bash
# init.sql — runs on first container start
CREATE TABLE IF NOT EXISTS users (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  name VARCHAR(255)
);

INSERT INTO users (email, name) VALUES
  ('alice@example.com', 'Alice'),
  ('bob@example.com', 'Bob');

Reset the database:

bash
docker compose down -v  # -v removes volumes
docker compose up -d

Override Files

Use docker-compose.override.yml for dev-specific settings:

yaml
# docker-compose.override.yml (auto-loaded)
services:
  api:
    command: npm run dev
    environment:
      - DEBUG=true
      - LOG_LEVEL=debug

For production, use an explicit file:

bash
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
Stay Updated

Get weekly IT automation tips

Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.

Subscribe Free →

Useful Commands

bash
# Start everything
docker compose up -d

# View logs
docker compose logs -f api

# Run a one-off command
docker compose exec api npm run migrate

# Rebuild after Dockerfile changes
docker compose up -d --build

# Stop and clean up
docker compose down

# Nuclear option — remove everything including volumes
docker compose down -v --rmi all

Profiles

Run optional services only when needed:

yaml
services:
  api:
    build: .
    ports:
      - "3000:3000"

  mailhog:
    image: mailhog/mailhog
    ports:
      - "8025:8025"
    profiles:
      - email

  adminer:
    image: adminer
    ports:
      - "8080:8080"
    profiles:
      - debug
bash
# Normal dev
docker compose up -d

# With email testing
docker compose --profile email up -d

# With everything
docker compose --profile email --profile debug up -d

---

Ready to go deeper? Check out our hands-on course: Docker Fundamentals — practical exercises you can follow along on your own machine.

Ready to learn by doing?

Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.

Share this article
LB
Luca Berton

Docker Captain, IT automation expert, Red Hat Summit & KubeCon speaker. Building hands-on education for DevOps engineers at CopyPasteLearn.

Related Articles

Explore topics

Browse more articles on the topics covered here.