Sachin Chaurasiya

Toolbox · Containers

Container Debugging

Get inside containers that have no shell, inspect namespaces, cgroups and capabilities, and trace what a process is doing.

Last reviewed
2026-09-18
On this page

Get a shell (or not)

CommandPurpose
docker exec -it <ctr> shIf the image has a shell
docker run --rm -it --pid=container:<ctr> --net=container:<ctr> nicolaka/netshootDebug sidecar sharing PID and network namespaces
kubectl debug -it <pod> --image=busybox:1.36 --target=<container>Ephemeral container in the pod
kubectl debug node/<node> -it --image=ubuntuCaution host-namespace debug pod with the node filesystem mounted at /host
nsenter -t <pid> -n ss -tulpnRun a host tool inside a container’s namespace

Find the process on the host

docker inspect --format '{{.State.Pid}}' <ctr>
crictl ps; crictl inspect <id> | jq .info.pid
ls -l /proc/<pid>/ns/            # namespaces
cat /proc/<pid>/status | grep -E 'Cap(Prm|Eff)'   # capabilities (decode with capsh --decode=)
cat /proc/<pid>/cgroup

Resource limits

CommandPurpose
docker stats --no-stream <ctr>Live usage
cat /sys/fs/cgroup/memory.max (inside container)Effective memory limit (cgroup v2)
cat /sys/fs/cgroup/memory.eventsoom_kill counter
kubectl describe pod <p> | grep -A2 'Last State'OOMKilled / exit codes

Filesystem and image

CommandPurpose
docker diff <ctr>Changed files
docker export <ctr> | tar -tvf - | headList container FS
docker save img:tag | tar -xf - -C /tmp/imgUnpack image layers
dive img:tagLayer explorer (external tool)
docker image inspect img:tag --format '{{json .Config}}' | jqEntrypoint, env, user

Tracing

CommandPurpose
strace -f -p <pid> -e trace=openat,connectFile and network syscalls
ltrace -p <pid>Library calls
tcpdump -ni any -c 20 (in netshoot)Packets

Exit codes

CodeMeaning
0Success
1Application error
125Docker daemon error
126Command not executable
127Command not found
137SIGKILL (often OOM)
139SIGSEGV
143SIGTERM