如何在Dockerfile中向PYTHONPATH添加路径 [英] How do you add a path to PYTHONPATH in a Dockerfile
问题描述
如何在Dockerfile中向PYTHONPATH添加路径?这样,当容器运行时,它具有正确的PYTHONPATH吗?我是docker的新手.
How do you add a path to PYTHONPATH in a Dockerfile? So that when the container is run it has the correct PYTHONPATH? I'm completly new to docker.
我已经将ENV PYTHONPATH "${PYTONPATH}:/control"
添加到了Dockerfile中,因为我想将目录/control
添加到PYTHONPATH
中.
I've added ENV PYTHONPATH "${PYTONPATH}:/control"
to the Dockerfile as I want to add the directory /control
to PYTHONPATH
.
当我使用docker exec -it trusting_spence bash
访问容器bash并打开python并运行目录control
下的命令时,不在列表中.
When I access the containers bash with docker exec -it trusting_spence bash
and open python and run the commands below the directory control
is not on the list.
import sys
print(sys.path)
import sys
print(sys.path)
FROM python:2
RUN pip install requests\
&& pip install pymongo
RUN mkdir control
COPY control_file/ /control
ENV PYTHONPATH "${PYTONPATH}:/control"
CMD ["python","control/control_file/job.py"]
推荐答案
只需在Dockerfile
中添加ENV
条目:
ENV PYTHONPATH "${PYTHONPATH}:/your/custom/path"
或在启动脚本中设置PYTHONPATH
.
这篇关于如何在Dockerfile中向PYTHONPATH添加路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!