1

I need to run python script in the docker container. This script has import of the psutil module. I created image and after running it I'm getting error:

File "/usr/src/app/metrics.py", line 1, in <module>
   import psutil
ModuleNotFoundError: No module named 'psutil'

Locally my script works cause i installed this module through "python -m pip install psutil" command. I've tried to simulate this action in dockerfile through: "CMD python -m pip install psutil" but it doesn`t work. What am i doing wrong? Dockerfile content:

FROM python:3.8.2-buster
WORKDIR /usr/src/app
COPY metrics.py .
RUN pip install --upgrade pip
CMD python -m pip install psutil
CMD python /usr/src/app/metrics.py

1 Answer 1

0

According to https://docs.docker.com/engine/reference/builder/ "There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect."

Maybe you just want to install psutil using another RUN?

FROM python:3.8.2-buster
WORKDIR /usr/src/app
COPY metrics.py .
RUN pip install --upgrade pip
RUN python -m pip install psutil
CMD python /usr/src/app/metrics.py
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.