diff --git a/pkg/kubelet/dockershim/helpers.go b/pkg/kubelet/dockershim/helpers.go index 83fa2cc907e..e7e3c31ed8c 100644 --- a/pkg/kubelet/dockershim/helpers.go +++ b/pkg/kubelet/dockershim/helpers.go @@ -213,6 +213,12 @@ func getSandboxSecurityOpts(sandboxConfig *runtimeApi.PodSandboxConfig, seccompP } func getNetworkNamespace(c *dockertypes.ContainerJSON) string { + if c.State.Pid == 0 { + // Docker reports pid 0 for an exited container. We can't use it to + // check the network namespace, so return an empty string instead. + glog.V(4).Infof("Cannot find network namespace for the terminated container %q", c.ID) + return "" + } return fmt.Sprintf(dockerNetNSFmt, c.State.Pid) } diff --git a/pkg/kubelet/dockertools/docker_manager.go b/pkg/kubelet/dockertools/docker_manager.go index eb7868ab938..96e0e8ac212 100644 --- a/pkg/kubelet/dockertools/docker_manager.go +++ b/pkg/kubelet/dockertools/docker_manager.go @@ -2531,6 +2531,13 @@ func (dm *DockerManager) GetNetNS(containerID kubecontainer.ContainerID) (string glog.Errorf("Error inspecting container: '%v'", err) return "", err } + if inspectResult.State.Pid == 0 { + // Docker reports pid 0 for an exited container. We can't use it to + // check the network namespace, so return an empty string instead. + glog.V(4).Infof("Cannot find network namespace for the terminated container %q", containerID.ID) + return "", nil + } + netnsPath := fmt.Sprintf(DockerNetnsFmt, inspectResult.State.Pid) return netnsPath, nil }