如何在Dockerfile中向PYTHONPATH添加路径 [英] How do you add a path to PYTHONPATH in a Dockerfile

查看:269
本文介绍了如何在Dockerfile中向PYTHONPATH添加路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆