{"record":{"id":"54e4c51e7790f7f8","repo":"slimtoolkit/slim","slug":"target-container-not-found","errorCode":null,"errorMessage":"target container not found","messagePattern":"target container not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/command/debug/handle_kubernetes_runtime.go","lineNumber":396,"sourceCode":"\t\t//doTTY = targetContainer.TTY\n\t\tlogger.WithField(\"data\", fmt.Sprintf(\"%#v\", targetContainer)).Trace(\"target container info\")\n\t}\n\n\tcontainerFound := false\n\tfor _, containerStatus := range pod.Status.ContainerStatuses {\n\t\tif containerStatus.Name == commandParams.TargetRef {\n\t\t\tcontainerFound = true\n\t\t\tif containerStatus.State.Running != nil {\n\t\t\t\ttargetContainerIsRunning = true\n\t\t\t\tlogger.Trace(\"target container is running\")\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif !containerFound {\n\t\tlogger.Errorf(\"Container %s not found in pod %s\", commandParams.TargetRef, podName)\n\t\txc.FailOn(fmt.Errorf(\"target container not found\"))\n\t}\n\n\tif !targetContainerIsRunning {\n\t\txc.Out.Info(\"wait.for.target.container\",\n\t\t\tovars{\n\t\t\t\t\"name\":      commandParams.TargetRef,\n\t\t\t\t\"pod\":       podName,\n\t\t\t\t\"namespace\": nsName,\n\t\t\t})\n\n\t\terr = waitForContainer(logger, xc, ctx, api, nsName, podName, commandParams.TargetRef, ctStandard)\n\t\tif err != nil {\n\t\t\tlogger.WithError(err).Error(\"waitForContainer\")\n\t\t\txc.FailOn(err)\n\t\t}\n\t}\n\n\t//'tty' config needs to be the same when creating & attaching","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/command/debug/handle_kubernetes_runtime.go#L378-L414","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nslim debug mypod --target contianer-1\n// after\nslim debug mypod --target container-1  # exact name from kubectl","handlingStrategy":"validation","validationCode":"pod=\"myapp-pod\"; target=\"app\"\nkubectl get pod \"$pod\" -o jsonpath='{.spec.containers[*].name}' | tr ' ' '\\n' | grep -qx \"$target\" || echo \"container $target not in pod $pod\"","typeGuard":null,"tryCatchPattern":"if err := runDebug(target); err != nil && strings.Contains(err.Error(), \"target container not found\") {\n    // list available containers and retry with a corrected name\n}","preventionTips":["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"],"tags":["kubernetes","container-not-found","debug"],"backgroundTag":"container-not-found","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}