Skip to content

fix: detect and clean up failed container after docker run -d#249

Merged
mbabic84 merged 1 commit into
mainfrom
fix/silent-network-error-on-recreate
Jul 13, 2026
Merged

fix: detect and clean up failed container after docker run -d#249
mbabic84 merged 1 commit into
mainfrom
fix/silent-network-error-on-recreate

Conversation

@mbabic84

Copy link
Copy Markdown
Owner

Summary

  • Detect and clean up failed containers after docker run -d when the container never reaches running state

Problem

When a user specifies an invalid --network value during kilo-docker sessions recreate, the container is created but never starts, leaving it in Docker's Created state. Some Docker versions return exit code 0 from docker run -d in this scenario, making the error undetectable. The user sees no error — the recreate command exits cleanly and the orphaned container is never cleaned up.

Solution

Add waitForContainerCreated() that polls container state after docker run -d for up to 5 seconds. If the container transitions to exited or created instead of running, it returns an error with the container's logs (which contain Docker's explanation, e.g. network service:nordvpn not found). The failed container is automatically cleaned up.

Changes

  • cmd/kilo-docker/docker.go — Add waitForContainerCreated() post-creation health check
  • cmd/kilo-docker/main.go — Integrate health check into runContainer default case, add container cleanup on both dockerRunDetached error and health check failure paths

Some Docker versions return exit code 0 from 'docker run -d' even when
the container cannot start (e.g. invalid network), leaving it in
'created' state. Add waitForContainerCreated() to poll container state
after detached run, and clean up orphaned containers on failure.
@mbabic84
mbabic84 merged commit 5f78ed9 into main Jul 13, 2026
1 check passed
@mbabic84
mbabic84 deleted the fix/silent-network-error-on-recreate branch July 13, 2026 14:51
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 3.50.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant