Docs / Cloud & DevOps / Container Orchestration with Docker Compose in Production

Container Orchestration with Docker Compose in Production

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 102 views · 1 min read

Production Compose File

services:
  app:
    image: myapp:${VERSION:-latest}
    restart: unless-stopped
    environment:
      - NODE_ENV=production
      - DATABASE_URL=${DATABASE_URL}
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: "1.0"
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

  db:
    image: postgres:16
    restart: unless-stopped
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=${DB_PASSWORD}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: redis-server --maxmemory 128mb --maxmemory-policy allkeys-lru

  nginx:
    image: nginx:alpine
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - /etc/letsencrypt:/etc/letsencrypt:ro
    depends_on:
      app:
        condition: service_healthy

volumes:
  pgdata:

Environment File

# .env (never commit this)
VERSION=1.2.3
DATABASE_URL=postgres://app:secret@db:5432/myapp
DB_PASSWORD=secret

Production Tips

  • Always use restart: unless-stopped
  • Set resource limits to prevent runaway containers
  • Use health checks for dependency ordering
  • Pin image versions (not :latest)
  • Configure log rotation

Deployment Workflow

docker compose pull
docker compose up -d --remove-orphans
docker compose ps
docker image prune -f

Was this article helpful?