Docker Compose Multi-Service Setup
Docker Compose configuration for a Node.js app with PostgreSQL, Redis, and Nginx reverse proxy.
# docker-compose.yml
version: '3.8'
services:
app:
build: .
ports:
- '3000:3000'
environment:
DATABASE_URL: postgres://app:secret@db:5432/mydb
REDIS_URL: redis://cache:6379
depends_on:
db:
condition: service_healthy
cache:
condition: service_started
restart: unless-stopped
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: secret
POSTGRES_DB: mydb
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U app']
interval: 5s
retries: 5
cache:
image: redis:7-alpine
ports:
- '6379:6379'
volumes:
- redisdata:/data
nginx:
image: nginx:alpine
ports:
- '80:80'
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- app
volumes:
pgdata:
redisdata:Sponsored
Docker Desktop — Container development made easy
Use Cases
- Local development environment with multiple services
- Staging environment replication
- Microservice architecture prototyping
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Kubernetes Deployment Configuration
Production-ready Kubernetes deployment with replicas, resource limits, health checks, and rolling updates.
Redis Docker Setup with Persistence
Docker Compose for Redis with persistence, password auth, memory limits, and a health check.
PostgreSQL Docker Setup with Init Script
Docker Compose for PostgreSQL with volume persistence, init scripts, and connection pooling.
Dockerfile Multi-Stage Build
Multi-stage Dockerfile for Node.js with build, prune, and minimal production image layers.