Bekzod Erkinov
Listen to Article
Loading...Zero-Downtime Deployment Script with Docker Compose: Migrations, Health Checks, Rollback
This post builds a ~100-line bash deployment automation script (zero-downtime in the blue/green sense described below) for a small Node + Postgres app on Docker Compose and nginx. It builds, backs up, migrates, health-checks, switches traffic and rolls back. I then shipped deliberately broken releases through it under a request loop. In my runs, a release that passes its healthcheck but returns 500 on / cost 13 and 15 failed requests with only a post-switch probe, and none with a pre-switch smoke test. If you later want this triggered from a pipeline, see the CI/CD pipelines with Jenkins and Docker guide.
Scope: "zero downtime" here means the old color is never stopped, so you can always swap back, not that requests never fail. Everything below ran on Docker Desktop on Windows 11 (Git Bash), where a bare docker compose exec takes about a second. I did not run it on Linux, so treat every timing and failed-request count as specific to this setup; drop export MSYS_NO_PATHCONV=1 on Linux.
Zero-downtime deployment with Docker Compose: the blue/green setup
The demo app is a Node 22 service (/, /version, /healthz) talking to Postgres 17. blue and green are the same image under two service names, and nginx sends traffic to one of them. Versions are pinned in the files below (node:22-alpine, postgres:17-alpine, nginx:1.27-alpine, pg 8.13.1); in the re-run for this post docker version printed 29.7.2 for client and server and docker compose version --short printed 5.3.1.
compose.yml. The [healthcheck](https://docs.docker.
Unlock Premium Content
You've read 30% of this article
What's in the full article
- Complete step-by-step implementation guide
- Working code examples you can copy-paste
- Advanced techniques and pro tips
- Common mistakes to avoid
- Real-world examples and metrics
Don't have an account? Start your free trial
Join 10,000+ developers who love our premium content
Keep reading
Complete Solution: Scaling a Node.js Application with Kubernetes and Docker
29 min · 986 views
Data ScienceMastering CI/CD Pipelines with Jenkins and Docker: A Deep Dive into Automated Deployment and Testing
14 min · 969 views
PerformanceComplete Solution: Building a Secure E-commerce Website with Stripe and Laravel
28 min · 229 views
Bekzod Erkinov
AuthorFounder of NextGenBeing. Software engineer working with Laravel, Python, and cloud infrastructure. Writes about patterns that actually hold up in production. Based in Tashkent, Uzbekistan.
Get the AI-Assisted Developer's Field Guide
The workflow, prompts, and tools I use to ship faster with AI — free when you subscribe. Plus new deep-dives in your inbox. No spam, unsubscribe anytime.
Comments (0)
Please log in to leave a comment.
Log In