slimtoolkit/slim · error
target container not found
Error message
target container not found
What it means
During a debug session, the tool looks up the container named by TargetRef inside the resolved pod's container statuses (standard, init, and ephemeral). If no status matches that name, the command fails with this error. It means the requested container does not exist in the pod, not that it is merely stopped.
Source
Thrown at pkg/app/master/command/debug/handle_kubernetes_runtime.go:396
//doTTY = targetContainer.TTY
logger.WithField("data", fmt.Sprintf("%#v", targetContainer)).Trace("target container info")
}
containerFound := false
for _, containerStatus := range pod.Status.ContainerStatuses {
if containerStatus.Name == commandParams.TargetRef {
containerFound = true
if containerStatus.State.Running != nil {
targetContainerIsRunning = true
logger.Trace("target container is running")
}
break
}
}
if !containerFound {
logger.Errorf("Container %s not found in pod %s", commandParams.TargetRef, podName)
xc.FailOn(fmt.Errorf("target container not found"))
}
if !targetContainerIsRunning {
xc.Out.Info("wait.for.target.container",
ovars{
"name": commandParams.TargetRef,
"pod": podName,
"namespace": nsName,
})
err = waitForContainer(logger, xc, ctx, api, nsName, podName, commandParams.TargetRef, ctStandard)
if err != nil {
logger.WithError(err).Error("waitForContainer")
xc.FailOn(err)
}
}
//'tty' config needs to be the same when creating & attachingView on GitHub (pinned to 81940d17fa)
Solutions
- List the pod's actual container names (`kubectl get pod <pod> -o jsonpath='{.spec.containers[*].name}'`) and use an exact name as the target.
- Verify the correct pod was selected; if multiple pods exist, pass an explicit pod instead of relying on auto-detection.
- Check whether the container was renamed or removed in a recent deployment and update the target reference.
- If the target is an ephemeral/debug container, confirm it still exists (ephemeral containers vanish with pod restarts).
Example fix
// before slim debug mypod --target contianer-1 // after slim debug mypod --target container-1 # exact name from kubectl
Defensive patterns
Strategy: validation
Validate before calling
pod="myapp-pod"; target="app"
kubectl get pod "$pod" -o jsonpath='{.spec.containers[*].name}' | tr ' ' '\n' | grep -qx "$target" || echo "container $target not in pod $pod" Try / catch
if err := runDebug(target); err != nil && strings.Contains(err.Error(), "target container not found") {
// list available containers and retry with a corrected name
} Prevention
- Always copy container names exactly from kubectl output
- Pass an explicit pod when multiple pods exist in the namespace
- Re-check targets after every deployment rollout
When it happens
Trigger: Running `debug <target> ...` (via OnCommand -> HandleKubernetesRuntime) where commandParams.TargetRef names a container that is absent from the pod's spec/status after ensurePod resolved the pod.
Common situations: Typo in the container name; targeting a pod's pod-name instead of a container name; container was removed in a recent deployment rollout; sidecar removed; using the wrong pod because the auto-selected pod (ensurePod picks the first pod) is not the one holding the container.
Related errors
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/54e4c51e7790f7f8.
Report an issue: GitHub.