Container Basics On Linux (Namespaces/Cgroups)
Stop your container from thinking it has all the host RAM
🧩 The Challenge
You’ve probably seen a container crash with an OOM killer log even though your host dashboard says there is plenty of memory left. It happens because the container can see the host’s total RAM via free or top, which tricks your application into trying to allocate way more than the cgroup limit allows.
💡 The Fix
Use lxcfs to provide a virtualized view of the system files so your apps report the correct memory limits instead of the host total. It makes your containers behave like actual isolated machines.
apt install lxcfs
mount -t fuse.lxcfs /var/lib/lxcfs /var/lib/lxcfs
docker run -v /var/lib/lxcfs/proc/meminfo:/proc/meminfo:rw -v /var/lib/lxcfs/proc/uptime:/proc/uptime:rw ... your-image
⚙️ Why It Works
Mounting these virtual files forces the kernel to serve up cgroup-aware stats to the process inside the namespace. Apps that check /proc/meminfo to tune their garbage collection or cache buffers will finally respect the container boundaries.
🚀 Pro-Tip: Check if your Java heap settings are set to auto-detect memory, because that is the most common reason you will trip over this.
Linux Tips & Tricks | © ngelinux.com | 8/13/2026
