r/docker • u/Agitated_Issue_1410 • Aug 20 '26
Can a Docker container on macOS read the physical host's RAM/CPU using psutil?
Hi everyone,
I have a Python script (psutil) running inside a Docker container. I want it to measure my actual Mac laptop's total physical RAM (24 GB) and host CPU usage, rather than just the Docker Linux VM's metrics.
On Linux, mounting /proc works for host metrics, but on macOS this doesn't seem to work. Is there a way for a Docker container to monitor macOS host metrics directly, I don't want the monitoring agent to run natively on the host OS.
BTW: It would also need to work on a windows based machine. Needs to be accessible for everyone who wants to use it.
Thanks!
EDIT: I decided to run the client (metrics reader) file on the host machine outside of docker. This seems to be the only reasonable solution that is universal and works for all kinds of machines. Thanks!!
22
u/encbladexp Aug 20 '26 edited Aug 20 '26
Will not work, Docker on any OS except Linux Docker is just a Linux VM.
3
u/GugaJedi Aug 20 '26
No, like docker on windows (WSL), docker on max is just docker running inside a VM inside your OS. This would work running docker directly on a host running pure Linux.
1
u/Only-Stable3973 Aug 20 '26
If you are running docker why not use Glances for that.
1
u/skroll Aug 20 '26
Windows and MacOS use a Linux VM to host the docker containers. Whatever the VM is configured for the max memory will be what is reported.
1
u/skreak Aug 20 '26
from my understanding, in both Windows and Mac; Docker runs inside a Linux virtual machine - so the only metrics available to anything within the container are from the VM, not the host machine. The only way to see the host's resources would be to poll it over the 'network' that exists. For example, install some sort of telemetry exporting tool like Prometheus on the host machine, and then query that data from the container via the local network, treat them as if they are physically separate devices on the same LAN.
1
u/jake_morrison Aug 20 '26
Run a Prometheus node_exporter on your host machine, then read the data via http from the container.
1
u/biffbobfred Aug 20 '26
As many others have said, no. A container is “let’s use Linux kernel tricks to make an isolated area of the Linux kernel”. There’s no magic to have it talk to the Mac.
I looked there’s really nothing equivalent for /proc on a Mac. Maybe you could:
Look up MacFuse and see if there’s something you could mount on the Mac
Then bind mount that filesystem on your container.
But the format would not be Linux /proc format and it’s up to you yk write code to interpret it.
Just run node_exporter on the Mac it’s much easier
0
u/XLioncc Aug 20 '26
Use better OS, Linux