Production Deployment Strategies
Transitioning containers from a local development machine to a mission-critical production server requires bulletproof infrastructure practices. In this chapter, learn how to manage container stacks as nativesystemd services, prevent server outages caused by unrotated log files, and orchestrate automated rolling updates.
1. Managing Docker Compose as a Native Systemd Service
On dedicated Linux VPS hosts (Ubuntu, Debian, RHEL), do not manually start containers in an SSH terminal. Register your Compose stack with systemd so that Linux automatically boots the containers upon server reboot and shuts them down gracefully during system updates:
# Create unit file: /etc/systemd/system/docker-compose-app.service
[Unit]
Description=Enterprise Docker Compose Application Service
Requires=docker.service
After=docker.service network-online.target
Wants=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/production-app
ExecStart=/usr/bin/docker compose up -d --remove-orphans
ExecStop=/usr/bin/docker compose down
ExecReload=/usr/bin/docker compose up -d --build
TimeoutStartSec=0
[Install]
WantedBy=multi-user.targetEnable and start the service with standard systemd commands:
sudo systemctl daemon-reload
sudo systemctl enable --now docker-compose-app.service
sudo systemctl status docker-compose-app.service2. Preventing Server Outages: Production Log Rotation
The Silent Production Killer: Unbounded Logs
By default, Docker uses the json-file logging driver with zero size restrictions. A high-throughput web service or noisy error loop will write gigabytes of JSON to /var/lib/docker/containers/until the server hard drive hits 100% capacity, freezing the OS and crashing all databases!
Configure global, automatic log rotation across all containers in /etc/docker/daemon.json:
// /etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "50m",
"max-file": "3"
},
"live-restore": true
}This guarantees that no container will ever store more than 150 MB of logs (three 50 MB rotated files) on disk. Reload the daemon using sudo systemctl reload docker to apply.
3. Automated Continuous Updates with Watchtower
Watchtower is an open-source daemon that monitors your running containers, periodically queries your container registry for newer image digests, and executes zero-touch rolling updates with the original runtime flags:
# Deploy Watchtower to inspect running containers every 5 minutes (300 seconds)
docker run -d \
--name watchtower \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower \
--interval 300 \
--cleanup4. Production Cloud Platform Spectrum
| Platform | Management Overhead | Auto-Scaling | Best Fit Workload |
|---|---|---|---|
| Cloud VPS (Ubuntu + Compose) | Medium (Self-managed OS) | Manual / Vertical | Early startups, internal tools, cost-conscious APIs ($5 – $40/mo). |
| AWS ECS with Fargate | Low (Serverless containers) | Automatic Horizontal | Enterprise production microservices without Kubernetes complexity. |
| Google Cloud Run | Near-Zero (Scale to 0) | Instant Sub-second | Event-driven APIs, webhooks, bursty HTTP workloads. |
| Kubernetes (EKS / GKE) | High (Full cluster management) | Global multi-region | Large engineering organizations managing hundreds of microservices. |
Next Up: Docker Cleanup & Maintenance
In Chapter 19, learn how to audit disk usage, safely purge dangling images and build caches, and automate prune cron jobs.
Chapter 19: Cleanup & Maintenance →