Docker Compose in Production? Yes, Really.
There's a common misconception that Docker Compose is only for development. At Circuvent, we run 8 production applications on Docker Compose, and here's why it works.
When Docker Compose Makes Sense
Our Production docker-compose.yml Pattern
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
target: production
restart: unless-stopped
ports:
- "127.0.0.1:3000:3000"
environment:
- NODE_ENV=production
- DATABASE_URL=${DATABASE_URL}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
resources:
limits:
memory: 512M
cpus: '0.5'
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
db:
image: postgres:16-alpine
restart: unless-stopped
volumes:
- pgdata:/var/lib/postgresql/data
- ./backups:/backups
environment:
- POSTGRES_PASSWORD=${DB_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
nginx:
image: nginx:alpine
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./certs:/etc/nginx/certs:ro
depends_on:
app:
condition: service_healthy
volumes:
pgdata:Health Checks Are Non-Negotiable
Every service must have a health check. Without them, Docker will route traffic to containers that aren't ready.
Zero-Downtime Deploys
Our deployment script:
#!/bin/bash
set -euo pipefail
echo "Pulling latest images..."
docker compose pull
echo "Building new containers..."
docker compose build --no-cache app
echo "Rolling update..."
docker compose up -d --no-deps app
echo "Waiting for health check..."
timeout 60 bash -c 'until docker compose exec app curl -sf http://localhost:3000/health; do sleep 2; done'
echo "Cleaning up old images..."
docker image prune -f
echo "Deployment complete!"Monitoring
We use a lightweight monitoring stack:
Backup Strategy
Automated daily backups with 30-day retention:
# Run daily via cron
docker compose exec db pg_dump -U postgres app_db | gzip > "/backups/app_db_$(date +%Y%m%d).sql.gz"
find /backups -name "*.sql.gz" -mtime +30 -delete