[英]How to import python module running script in docker container?
I need to run python script in the docker container.我需要在 docker 容器中运行 python 脚本。 This script has import of the psutil module.
该脚本导入了psutil模块。 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.我的脚本在本地工作是因为我通过“python -m pip install psutil”命令安装了这个模块。 I've tried to simulate this action in dockerfile through:
"CMD python -m pip install psutil"
but it doesn`t work.我试图通过以下方式在 dockerfile 中模拟此操作:
"CMD python -m pip install psutil"
但它不起作用。 What am i doing wrong?我究竟做错了什么? Dockerfile content:
Dockerfile 内容:
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
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."根据https://docs.docker.com/engine/reference/builder/ “一个 Dockerfile 中只能有一个 CMD 指令。如果你列出了多个 CMD,那么只有最后一个 CMD 才会生效。”
Maybe you just want to install psutil
using another RUN
?也许您只想使用另一个
RUN
安装psutil
?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.