Docker Community Forums

Share and learn in the Docker community.

Want to access the host device resource information from the docker container

docker

(Souvik91) #1

Hi All,

I am a new bee…in the Docker world…actually, I’m facing some problem to get the host device information. Before, I’ll ask my question…I’d like to explain a bit of my working scenario and code…so that might help you to understand my problem.

I want to know the various resource components (i.e., RAM, CPU, Storage, Power, OS, Network etc.) information of a device and also the location of the device. So, I write down some simple python program using the following python package -

  • psutil

  • cpuinfo

  • platform

  • geocoder

So, whenever, I used to run my code on the host machine…it is perfectly working and providing me with the desired output, but after that, I tried to containerizing my code and created the docker image. Then the problem is raised …now it is providing the information of resource components of the container. But I want to get host device resource information rather than getting the container’s resources components information.

I’m sharing my Dockerfile code in the below:

FROM python:3
RUN mkdir /var/app
WORKDIR /var/app
ADD venv/ venv/
ADD device_info.py/ .
RUN bash -c 'source venv/Scripts/activate’
RUN bash -c 'pip3 install geocoder’
RUN bash -c 'pip3 install py-cpuinfo’
RUN bash -c 'pip3 install psutil’
CMD [ “python”, “./device_info.py” ]

So, will anyone please help me what should I do…and what are the things should be added in the Dockerfile to get the host device information… Thanking all of you in advance.


(David Maze) #2

The general point of running things in Docker containers is to be isolated from this sort of detail. I’d recommend running your process directly on the host.

While there are things you can add to “break out” of the Docker box, they’re things that would need to be specified on the docker run command. You can’t specify in a Dockerfile that containers based on an image should always run in privileged mode or always have access to some host device, for instance (this would make it very hard to trust third-party images).

I feel like what you’re actually looking for is something like the Debian or RPM package build systems, which would give you consistent way to package up and distribute applications that run on the host, since you actively don’t want the isolation that Docker provides.


(Souvik91) #3

Yes, you are right…so can you please tell me how I can break out from the Docker box and say to docker image to provide me with the host resource information details rather than delivering the container information…can you please give me some example of some command … Thanking you in advance.