See what your container *really* sees with `nsenter`

Container Basics On Linux (Namespaces/Cgroups)

See what your container *really* sees with `nsenter`

🧩 The Challenge

You’re SSH’d into a host and a container process is chewing up CPU, but `ps aux` on the host shows all these weirdly numbered PIDs. Trying to track down *which* process it is feels like trying to find a needle in a haystack blindfolded.

💡 The Fix

There’s a killer tool that lets you jump right into a container’s process tree, so you can see exactly what’s going on from its perspective. Seriously, this saves so much guessing.

ps aux | grep your-container-app
PID_FROM_PREVIOUS_COMMAND=$(...) # Get the PID of the app from the host ps aux output
nsenter --target $PID_FROM_PREVIOUS_COMMAND --all --mount --ipc --net --pid --uts --user ps aux

⚙️ Why It Works

`nsenter` is the magic here. By specifying the target PID from the host and using the `–all` flag (or individual flags like `–pid`, `–net`, etc.), it allows you to execute commands *within* the namespaces that process is operating in. So, `ps aux` run via `nsenter` shows you the processes *as the container sees them*.

🚀 Pro-Tip: Pipe the output of `nsenter ps aux` directly into `grep` if you’re hunting a specific process name within the container’s view.

Linux Tips & Tricks | © ngelinux.com | 9/6/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted