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:
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: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:
services:
api:
build: .
volumes:
- ./src:/app/src
- /app/node_modules # Prevent overwriting container's node_modules
command: npm run devThe /app/node_modules anonymous volume keeps the container's installed packages separate from your host.
Database Seeding
Place SQL files in the init directory:
# 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:
docker compose down -v # -v removes volumes
docker compose up -dOverride Files
Use docker-compose.override.yml for dev-specific settings:
# docker-compose.override.yml (auto-loaded)
services:
api:
command: npm run dev
environment:
- DEBUG=true
- LOG_LEVEL=debugFor production, use an explicit file:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -dGet weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Useful Commands
# 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 allProfiles
Run optional services only when needed:
services:
api:
build: .
ports:
- "3000:3000"
mailhog:
image: mailhog/mailhog
ports:
- "8025:8025"
profiles:
- email
adminer:
image: adminer
ports:
- "8080:8080"
profiles:
- debug# Normal dev
docker compose up -d
# With email testing
docker compose --profile email up -d
# With everything
docker compose --profile email --profile debug up -dRelated Posts
- Getting Started with Docker for Docker basics
- Docker Multi-Stage Builds for production images
- Building REST APIs with Node.js for the API side
---
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.
Related Articles
TypeScript Express Tutorial 2026
Build a production REST API with TypeScript and Express. Complete tutorial covering project setup, routing, middleware, and deployment.
DevContainers for Team Development
Dev Containers standardize development environments using Docker. Learn how to set up devcontainers for your team with VS Code, GitHub Codespaces, and custom.
Environment Variables Best Practices
Handle environment variables correctly. Dotenv files, Docker secrets, Kubernetes ConfigMaps, twelve-factor methodology, and security pitfalls.
Docker Compose Production Patterns
Production-ready Docker Compose patterns. Health checks, resource limits, structured logging, secrets management, and multi-environment configs.
Docker Compose Tutorial for Devs
Master Docker Compose for local development. Multi-service stacks with databases, caching, and hot reload in one command.
Docker Image Optimization Guide
Reduce Docker image size by up to 90%. Multi-stage builds, layer caching, distroless base images, and build-time best practices.
Explore topics
Browse more articles on the topics covered here.