fix(startup): self-heal nested Docker daemon after in-place container restart - #194
Merged
Conversation
… restart
When the host's docker-ce package is upgraded (or the host reboots),
Docker restarts each workspace container in place via `restart =
unless-stopped` rather than recreating it. The nested `dockerd` inside
runs as a bare background process with nothing managing its lifecycle,
so it gets killed uncleanly, leaving a stale /var/run/docker.pid that
makes the next `dockerd` refuse to start ("process with PID ... is
still running") even though nothing is running. Startup only checked
for the socket *file*, not daemon health, so the workspace reported
healthy while Docker (and therefore DDEV) stayed broken until someone
manually restarted the workspace.
Verified end-to-end against staging-coder.ddev.com (d12-1): both a
host-level `docker-ce` upgrade and a full host reboot now recover on
their own.
Fix has two halves, extracted into a shared modules/docker-daemon
module (vendored into each template dir like claude-remote-control)
since the logic was identical across all three templates:
- Shutdown: gracefully SIGTERM (then SIGKILL after a timeout) the
nested dockerd before the container is torn down, so it doesn't
leave corrupted/stale state behind in the first place.
- Startup: verify actual daemon health via `docker info`, not just
socket presence; clear stale pidfile/socket and retry once before
giving up, so a container that does get killed uncleanly (e.g. by a
hard host power-cut) still recovers without manual intervention.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
4 tasks
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dockerdinside each workspace container runs as a bare background process with no init system managing it. When something outside Coder restarts the container in place (a hostdocker-cepackage upgrade, or a host reboot — both use the samerestart = unless-stoppedpath),dockerdgets killed uncleanly, leaving a stale/var/run/docker.pidthat makes the nextdockerdrefuse to start even though nothing is running. Startup only checked for the socket file's existence, not daemon health, so the workspace showed as healthy in Coder while Docker (and DDEV) stayed broken until someone manually restarted the workspace.docker info(not just the socket file), clears stale pidfile/socket state, and retries once before giving up.modules/docker-daemonmodule (vendored into each template dir the same waymodules/claude-remote-controlalready is) since the logic was identical across all three templates — replaces ~40 duplicated lines per template with a two-line module call.Test plan
terraform fmt -recursivecleanmake validate— all three templates validmake test-templates— all Terraform mock tests passd12-1:sudo apt upgradeofdocker-ceon the host (restartsdocker.service, which restarts the workspace container in place) — Docker self-healed, no manual restart needed