Peek inside a container process namespace without breaking a sweat
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
