Container Basics On Linux (Namespaces/Cgroups)
Peek inside a container process namespace without breaking a sweat
š§© The Challenge
Youāre staring at a container thatās acting up, but you canāt see the processes inside it from your host shell. Itās like trying to debug a locked room while standing on the outside.
š” The Fix
Use nsenter to hop directly into the containerās process namespace and see exactly what the application sees. Youāll stop guessing if your PID 1 is actually running your service or just a shell wrapper.
PID=$(docker inspect --format '{{.State.Pid}}' <container_name_or_id>)
nsenter -t $PID -m -u -n -p ps aux
āļø Why It Works
By grabbing the process ID of the container, you tell the kernel to shift your view into that specific set of namespaces. It effectively lets you play ghost inside the containerās environment without needing an SSH server installed inside the image.
š Pro-Tip: Alias this to āenter-containerā with a name argument to save your sanity during production incidents.
Linux Tips & Tricks | Ā© ngelinux.com | 9/5/2026
