Zero-Downtime Deployment Script with Docker Compose: Migrations, Health Checks, Rollback - NextGenBeing
Back to discoveries

Zero-Downtime Deployment Script with Docker Compose: Migrations, Health Checks, Rollback

A tested bash and Docker Compose deploy script with migrations, health checks, a smoke test and rollback, run against deliberately broken releases.

Performance Premium Content 12 min read
Bekzod Erkinov

Bekzod Erkinov

May 5, 2026 • 79 views
Zero-Downtime Deployment Script with Docker Compose: Migrations, Health Checks, Rollback
Photo by Đào Hiếu on Unsplash
Size:
Height:
12 min read 4,494 words Focus mode: Eye care:

Listen to Article

Loading...
0:00 / 0:00
0:00 0:00
Low High
0% 100%
⏸ Paused ▶️ Now playing... Ready to play ✓ Finished

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

Join 10,000+ developers who love our premium content

Bekzod Erkinov

Bekzod Erkinov

Author

Founder of NextGenBeing. Software engineer working with Laravel, Python, and cloud infrastructure. Writes about patterns that actually hold up in production. Based in Tashkent, Uzbekistan.

Free guide

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

Related Articles

Don't miss the next deep dive

Get one well-researched tutorial in your inbox each week. No spam, unsubscribe anytime.