slimtoolkit/slim · error
Container terminated
Error message
Container terminated
What it means
ErrContainerTerminated is returned from HandleKubernetesRuntime (and the debug runtime flow) when the specific container targeted for debugging has terminated. Even if the pod is running, an exited container cannot be attached to or instrumented.
Source
Thrown at pkg/app/master/command/debug/handle_kubernetes_runtime.go:1001
err := wait.PollImmediate(2*time.Second, 2*time.Minute, isPodRunning)
if err != nil {
return nil, "", err
}
return outputPod, podName, nil
}
const (
ctInit = "init"
ctStandard = "standard"
ctEphemeral = "ephemeral"
)
var (
ErrPodTerminated = errors.New("Pod terminated")
ErrPodNotRunning = errors.New("Pod not running")
ErrContainerTerminated = errors.New("Container terminated")
)
func waitForContainer(
logger *log.Entry,
xc *app.ExecutionContext,
ctx context.Context,
api *kubernetes.Clientset,
nsName string,
podName string,
containerName string,
containerType string) error {
logger.Tracef("waitForContainer(%s,%s,%s,%s)", nsName, podName, containerName, containerType)
isContainerRunning := func() (bool, error) {
pod, err := api.CoreV1().Pods(nsName).Get(ctx, podName, metav1.GetOptions{})
if err != nil {
return false, err
}View on GitHub (pinned to 81940d17fa)
Solutions
- Check container state with kubectl describe pod and pick a currently running container name
- Prevent the app from exiting during debugging or use an ephemeral debug container strategy
- Re-run the debug command immediately after restarting the container
Example fix
kubectl debug -it my-pod --image=busybox --target=my-app # debug via ephemeral container instead of attaching to the exited one
Defensive patterns
Strategy: validation
Validate before calling
cs, _ := clientset.CoreV1().Pods(ns).Get(ctx, pod, metav1.GetOptions{})
for _, st := range cs.Status.ContainerStatuses {
if st.Name == target && st.State.Running == nil {
return fmt.Errorf("container %s is not running", target)
}
} Try / catch
// Go
if errors.Is(err, ErrContainerTerminated) {
// re-run with a running container or use kubectl debug ephemeral container
} Prevention
- Verify the target container's state is Running before attaching
- Don't target init or already-finished sidecar containers
- Restart the workload if the app container keeps exiting
When it happens
Trigger: Selecting a container that exited before the debug attach; the target process crashes during waitForContainer; naming a sidecar/ephemeral container that already finished.
Common situations: Debugging an app container that crashed; wrong container name passed (e.g. an init container); short-lived containers that finish before the debugger connects.
Related errors
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/943430dd2791e80a.
Report an issue: GitHub.