Access host /proc

Hi,

I would like to expose a server monitoring app as a docker container. The app i have written relies on /proc to read system information like CPU utilization or disk stats. Thus i have to forward the information provided in hosts /proc virtual file system to my docker container.

So i made a simple image (using the first or second intro on docker website: Link) and started it:
docker run -v=/proc:/host/proc:ro -d hostfiletest
Assuming the running container could read from /host/proc to obtain information about the host system.

I fired up a console inside the container to check:
docker exec -it {one of the funny names the container get} bash
And checked the content of /host/proc.

Easiest way to check it was getting the content of /host/proc/sys/kernel/hostname - that should yield the hostname of the vm iam working on.
But i get the hostname of the container, while /host/proc/uptime gets me the correct uptime of the vm.

Do i miss something here? Maybe something conceptual?

Docker version 17.05.0-ce, build 89658be running on Linux 4.4.0-97-generic (VM)

Greetings
Peepe

UPDATE 31.10:

  • Fixed typo
1 Like

Hello
I’m having a similar issue,
Did you succeed in reading process information from the host, not the docker?
I read some reference that running as privileged container is not enough and some more setting in the container execution are required like refrencing host process and host proc, e.g ```
-h hostname
-v /var/run/docker.sock:/var/run/docker.sock -v /proc/:/host/proc/:ro
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro

Thanks
Nadav

Linux files are kinda tricky. Just because it looks like a file, doesn’t mean thats actaully a real file.
I think thats the problem here. This Stackoverflow answer says that the hostname is entirely stored in kernel memory and I think the file /proc/sys/kernel/hostname represents the hostname stored in kernel memory. Therefore it doesn’t matter if you mount the file from the host.

Mounting /etc/hostname does the trick tho.