Zero downtime
Add a health check so the new container is ready before the old one stops, and users stop seeing Bad Gateway.
By default Swarm stops the running container and starts the new one at the same time. Requests during startup get Bad Gateway. A health check makes Swarm wait until the new container is healthy.
Before you start
- A health endpoint in your app, for example
/healthreturning200. The example assumes port3000. curlinside the container.
Configure
Open Settings › Resources, then click Swarm settings in the Cluster settings card.
Paste into Health check and save.
{
"Test": ["CMD", "curl", "-f", "http://localhost:3000/health"],
"Interval": 30000000000,
"Timeout": 10000000000,
"StartPeriod": 30000000000,
"Retries": 3
}Redeploy.
Swarm runs curl inside the container every 30 seconds (values are nanoseconds) and retries 3 times before treating the container as unhealthy.
Verify
Deploy, start a second deployment, and reload /health while it builds. Without the health check you see Bad Gateway. With it, the old container keeps answering.
Next steps
- Revert failed releases automatically with Rollbacks.
