Container Basics On Linux (Namespaces/Cgroups)
Stop running top and wondering why your container metrics look like total garbage
đź§© The Challenge
You jump into a container and run top or free, only to see the stats for the entire host node staring back at you. It’s infuriating when you’re trying to debug memory pressure and the tools are lying to your face about the local environment.
đź’ˇ The Fix
Use nsenter to hook into the specific process namespace of your container so your diagnostic tools actually see what the container sees. You’ll stop chasing shadows and finally see the real resource consumption.
nsenter -t <pid> -m -u -i -n -p ps aux
⚙️ Why It Works
By switching into the mount, uts, ipc, network, and pid namespaces of the target process, your shell starts acting exactly like it’s living inside the container environment. The system calls for resource reporting get trapped within the container’s isolated view instead of bubbling up to the host level.
🚀 Pro-Tip: Alias this command in your bashrc with a regex to grab the PID automatically from your container engine and you’ll save yourself a minute of fumbling every single time.
Linux Tips & Tricks | © ngelinux.com | 8/31/2026
