1

Sorry guys, I am still quite new to Python. I am creating an application through Docker that monitors the cpu usage of a certain application running on the computer and it uses psutil. However when I run the application it doesn't work as it uses the Docker containers system etc. I was wondering if this is possible? This is my Dockerfile and I am working on a mac. I have read about mounting but I don't really understand how to do it.

FROM python:3.9

RUN apt-get update -y && \
    apt-get install -y python3-pip python3-dev

COPY requirements.txt .

WORKDIR /


RUN pip3 install -r requirements.txt


COPY . /


CMD ["python", "app/dbfile.py" ]
joshus
  • 31
  • 2

1 Answers1

1

You need to run this tool directly on the host system, perhaps in a Python virtual environment. You can't run it in Docker and especially not on MacOS.

A Docker container is generally intended to be isolated from its host system. A process running in a container can't see processes outside its own container, so a host-process-monitoring tool can't see the host processes it needs to monitor. On MacOS this is doubly true, since containers run in a hidden (Linux) virtual machine; even if you could disable the Docker pid namespace, you still wouldn't be able to see outside the VM to monitor (MacOS) host processes.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Okay thanks a lot for helping. That makes sense. I originally did it the way you specified in the first paragraph but as people who have never used python before will be using this script, I wanted to make it as easy as possible for them to run it. I guess I will have to stick with this way. Appreciate the help! – joshus Jul 20 '21 at 14:02
  • If you otherwise use Homebrew, https://docs.brew.sh/Python-for-Formula-Authors describes how to package a Python application so it can be `brew install`ed like any other application. – David Maze Jul 20 '21 at 14:09