Debug shell for containers without a shell (distroless) #14
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
OrbStack's debug shell gets you a shell with tools in any container, even distroless images. Krane's "open a shell" needs
shinside the container.What
--pid container:<id>,--network container:<id>, and the target's filesystem reachable via/proc/1/root, then open the terminal into it.Notes
Approach for the debug shell (research by Nye, our reviewer, tested on Docker 26 with bollard 0.20 against distroless root and nonroot targets). Upper Wolfjaw builds from this.
Krane #14: debug shell for distroless containers (Nye, Nov 30)
Tested on Docker 26.1.5 (Debian 13, arm64) with bollard 0.20. The test targets were distroless/static-debian12 in its root and :nonroot (uid 65532) variants, each running /pause with no sh.
docker execfails on them with rc 126. Probe program: issue14-probe-main.rs (it builds against bollard 0.20.0 as-is).Approach (works)
inspect_container(id). It needsstate.running == true. If not, show "Start the container to debug it".inspect_image(IMAGE). If that errors, runcreate_image(CreateImageOptionsBuilder::new().from_image(IMAGE).build(), None, None)and drain the stream (try_collect). Show a busy state or a toast while it runs. Default IMAGE:busybox:1.37, pinned (about 2 MB, multi-arch, has sh/ps/wget/nc/vi). Make it a setting so users can choosealpine(gets apk) or their own image.create_container(Some(CreateContainerOptionsBuilder::new().name(&name).build()), body):krane-debug-<short id>-<random 4 hex>. A fixed name gives a 409 on the second debug shell for the same target (tested).working_dir: /proc/1/root. runc refuses it ("cwd outside container mount namespace root, possible breakout"), so do the cd in the cmd as above.CAP_SYS_PTRACEis required for nonroot targets. Without it, /proc/1/root returns "Permission denied" (root helper, uid-65532 target). Running the helper as the target's uid doesn't help either (tested). For root targets it works without the cap.ipc_mode: container:<id>. It fails on Docker's default (private) IPC with "non-shareable IPC". It isn't needed for a shell.open_terminalplumbing (src/window/mod.rs), but with["docker", "start", "-ai", <helper id>]in place ofdocker exec -it. Factoropen_terminalto take the argv.Results in the shell (both targets):
psshows the target's PID 1, the network is the target's (same eth0/IP, 127.0.0.1 reaches its ports), and you start in /proc/1/root where the target's files are readable and writable.Cleanup
auto_removeremoves the helper when the shell exits, when start fails, and when the target stops while the shell is open (the helper is killed and removed; all tested, 0 left).list_containers(all, filters label=dev.krane.debug-shell)and force-remove any that aren't running, for crashes between create and start.dev.krane.debug-shellcontainers from the Containers list, or show them under their target.Fallback
docker exec -it id shfails with rc 126 (exec: "sh": executable file not found) inside the terminal, where Krane can't see it. Do the check before opening the terminal instead: bollardcreate_execwith cmd["sh","-c","true"],start_execdetached, theninspect_exec. If the exit code is 126 or 127 (or start errors), open the debug shell, or show "No shell in this image, open a debug shell?". Simpler alternative: always offer a separate "Debug shell" menu item, and only auto-fall back when the check says so.Caveats
docker(as open_terminal already does). If Krane's engine (or the #16 engine picker) differs from the CLI's current context, the terminal hits the wrong engine. Pass-H <host>/DOCKER_HOSTfrom Krane's connection to both the exec and debug commands. This matters for #16 too.container:pid/network modes; also not tested.--pid hostor--network host:container:joining still works (you inherit host ns). Containers that usenetwork_mode: container:Xthemselves can still be joined.docker debug/ OrbStack, and fine for a local dev tool.Calls for Jeremy
None that block building. The defaults (busybox:1.37, image as a setting, auto fallback with a prompt) follow the issue text.