Docker Compose handles multi-container applications efficiently on a Hong Kong VPS — without Kubernetes complexity. This guide covers production patterns: pinned image versions, health checks, resource limits, named volumes, environment separation, and zero-downtime updates.
Production docker-compose.yml
<code"># docker-compose.yml — production-ready template
name: myapp
services:
nginx:
image: nginx:1.27-alpine
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx:/etc/nginx/conf.d:ro
- /etc/letsencrypt:/etc/letsencrypt:ro
- nginx_cache:/var/cache/nginx
depends_on:
app:
condition: service_healthy
deploy:
resources:
limits: { cpus: '0.5', memory: 256M }
app:
image: registry.yourcompany.com/myapp:${APP_VERSION:-latest}
restart: unless-stopped
environment:
NODE_ENV: production
DATABASE_URL: ${DATABASE_URL}
REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
env_file: .env.production
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
resources:
limits: { cpus: '1.0', memory: 512M }
reservations: { memory: 256M }
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- postgres_data:/var/lib/postgresql/data
- ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits: { cpus: '1.0', memory: 1G }
redis:
image: redis:7-alpine
restart: unless-stopped
command: redis-server --requirepass ${REDIS_PASSWORD} --maxmemory 256mb --maxmemory-policy allkeys-lru
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 10s
timeout: 5s
retries: 3
deploy:
resources:
limits: { cpus: '0.5', memory: 512M }
volumes:
postgres_data:
driver: local
driver_opts:
type: none
o: bind
device: /opt/myapp/postgres # Named path — easy to backup
redis_data:
nginx_cache:
networks:
default:
name: myapp_network
Environment Management
<code"># .env.production (never commit to git) POSTGRES_DB=myapp_production POSTGRES_USER=myapp_user POSTGRES_PASSWORD=STRONG_DB_PASS REDIS_PASSWORD=STRONG_REDIS_PASS DATABASE_URL=postgresql://myapp_user:STRONG_DB_PASS@postgres:5432/myapp_production APP_VERSION=1.4.2 # Pin exact version for reproducible deployments # .env.staging — separate file for staging POSTGRES_DB=myapp_staging APP_VERSION=main-abc1234 # Use git sha for staging # Deploy staging: docker compose --env-file .env.staging up -d # Deploy production: docker compose --env-file .env.production up -d
Zero-Downtime Rolling Update
<code"># Update app container without downtime (Nginx continues serving) APP_VERSION=1.4.3 docker compose pull app docker compose up -d --no-deps --scale app=2 app # Start new alongside old sleep 10 curl -sf http://localhost/health && echo "New container healthy" docker compose up -d --no-deps --scale app=1 app # Remove old # Or use a deployment script: cat > deploy.sh << 'EOF' #!/bin/bash NEW_VERSION=$1 export APP_VERSION=$NEW_VERSION docker compose pull app docker compose up -d --no-deps app sleep 15 if curl -sf http://localhost/health; then echo "Deploy successful: $NEW_VERSION" else echo "Health check failed — rolling back" export APP_VERSION=previous docker compose up -d --no-deps app fi EOF
Production Operations
<code"># Common operations
docker compose ps # Status of all containers
docker compose logs -f app # Follow app logs
docker compose exec postgres psql -U myapp_user myapp_production # DB shell
docker compose exec app node -e "require('./src/db').migrate()" # Run migrations
# Scale app workers (if using multiple app containers)
docker compose up -d --scale app=3 # Run 3 app containers
# Backup PostgreSQL
docker compose exec postgres pg_dump -U myapp_user myapp_production \
| gzip > /backup/db_$(date +%Y%m%d).sql.gz
# Resource usage
docker stats $(docker compose ps -q) # CPU + memory per container
Conclusion
Docker Compose production deployment on a Hong Kong VPS is practical and reliable when configured correctly — pinned image versions prevent surprise breakage, health checks prevent traffic to unhealthy containers, resource limits prevent one service from consuming all VPS RAM, and named volume bind-mounts make backups straightforward. For teams serving Asia-Pacific users who want containers without Kubernetes overhead, Docker Compose with these patterns handles most production workloads on a 4–8 GB VPS.
Deploy with confidence: Browse Server.HK Hong Kong VPS plans — a 4 GB plan with NVMe storage handles a typical 3–4 container Compose stack including PostgreSQL and Redis.