Skip to content

fix(startup): self-heal nested Docker daemon after in-place container restart - #194

Merged
rfay merged 1 commit into
mainfrom
20260806_docker_survival
Aug 8, 2026
Merged

fix(startup): self-heal nested Docker daemon after in-place container restart#194
rfay merged 1 commit into
mainfrom
20260806_docker_survival

Conversation

@rfay

@rfay rfay commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Nested dockerd inside 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 host docker-ce package upgrade, or a host reboot — both use the same restart = unless-stopped path), dockerd gets killed uncleanly, leaving a stale /var/run/docker.pid that makes the next dockerd refuse 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.
  • Fixes both ends: shutdown now gracefully stops the nested daemon (SIGTERM, then SIGKILL after a timeout) before the container is torn down; startup verifies actual daemon health via docker info (not just the socket file), clears stale pidfile/socket state, and retries once before giving up.
  • Extracted into a shared modules/docker-daemon module (vendored into each template dir the same way modules/claude-remote-control already 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 -recursive clean
  • make validate — all three templates valid
  • make test-templates — all Terraform mock tests pass
  • Pushed to staging-coder.ddev.com and verified live on workspace d12-1:
    • sudo apt upgrade of docker-ce on the host (restarts docker.service, which restarts the workspace container in place) — Docker self-healed, no manual restart needed
    • Full host reboot — same result

… 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>
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-08-08 00:29 UTC

@rfay
rfay merged commit 436888a into main Aug 8, 2026
21 of 25 checks passed
@rfay
rfay deleted the 20260806_docker_survival branch August 8, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant