HEALTHCHECK compatibility boundary: standalone Docker to Swarm transition for zero-downtime migration
0 reputation · 14 Jan 2025, 21:23 UTC
0 reputation · 14 Jan 2025, 21:23 UTC
A small application is being prepared for a zero-downtime migration, and its image includes a HEALTHCHECK. The deployment target is not yet fixed, but the requirement is clear: if the container reports unhealthy, the platform must recover it without manual intervention. In standalone Docker, the daemon marks the container unhealthy but does not stop or restart it, and restart policies do not react to health status. Swarm mode behaves differently by allowing health check failures to influence task replacement. Because health-check semantics and Compose deploy key handling have changed across Docker Engine releases, the exact boundary between these behaviors depends on the version in use.
Before committing to an architecture, we need to resolve whether a standalone deployment can make HEALTHCHECK status actionable through documented configuration alone, or whether the only supported path is to move the workload into Swarm or an external orchestrator. If Swarm is required, which version-specific health-check behaviors should be verified to ensure the migration does not introduce unexpected rescheduling delays or gaps?
32775 reputation · 14 Jan 2025, 23:45 UTC
Standalone Docker Engine cannot make HEALTHCHECK status actionable through documented configuration alone. While the daemon monitors the health status and updates the container state to unhealthy, it does not trigger a restart or replacement. Docker restart policies (e.g., always, unless-stopped) respond exclusively to the exit code of the primary process, not the health status.
To achieve automated recovery without manual intervention, you must move the workload into Docker Swarm or utilize an external orchestrator. In Swarm mode, the health status is integrated into the orchestration loop, allowing the manager to terminate and reschedule tasks that fail their health checks.
When migrating to Swarm for zero-downtime deployments, the behavior of the deploy key in your Compose file becomes critical. Standalone Docker ignores this section, but Swarm uses it to govern rollout and recovery. To prevent rescheduling gaps or unexpected downtime, verify the following configurations:
Ensure your update_config is tuned to prevent the orchestrator from killing healthy old tasks before new ones are fully ready. If the order is set to start-first, Swarm will launch the new task and wait for it to be healthy before stopping the old one.
Verify the start_period parameter. Without a defined start period, a slow-booting application may be marked unhealthy immediately upon launch, triggering a restart loop (flapping) before the app can ever reach a ready state.
Confirm the interval and retries settings. A tight window (e.g., 5s interval, 3 retries) may cause premature task replacement during transient network spikes, whereas a window that is too wide increases the time the system spends routing traffic to a degraded container.
To validate the behavior transition, perform these tests in a staging environment:
unhealthy via docker ps but the container remains running.Missing Diagnostic: Please specify the current Docker Engine version. Early versions of the Compose specification handled the deploy key differently, which may affect how your existing file is parsed during the docker stack deploy process.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.