Why does `free -m` inside a container show host memory?
AdvancedConceptContainers, VMs & Isolation Internals
Answer
/proc/meminfo is not namespaced; it reports the host. The limit lives in cgroup files. This causes JVMs, Node and others to size heaps wrongly unless they are cgroup-aware (JDK 10+/8u191+, GOMEMLIMIT, --max-old-space-size). lxcfs can fake /proc files but is rarely needed now.
More on Containers, VMs & Isolation Internals
What is a container, in one sentence?BeginnerHow do containers differ from virtual machines?BeginnerCan a Linux container run a Windows application, or the reverse?IntermediateWhat are Linux namespaces? Name the ones Docker uses.BeginnerWhat are cgroups and what do they do for containers?BeginnerWhat is PID 1 in a container and why does it matter?Intermediate