我稍微修改了这个Dockerfile来支持我的特定用例: 我需要指定自己的PyPi
服务器, 我们发布内部库的地方。通常可以通过指定pip.conf
文件或通过向pip
传递命令行选项来实现。
我正在尝试使用以下内容:
FROM python:3.5
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ONBUILD COPY requirements.txt /usr/src/app/
# 1st try: set the env variable and use it implicitely. Does not work!
# ENV PIP_CONFIG_FILE pip.conf
# ONBUILD RUN pip install --no-cache-dir -r requirements.txt
# 2nd try: set once the env variable, just for this command. Does not work!
# ONBUILD RUN PIP_CONFIG_FILE=pip.conf pip install --no-cache-dir -r requirements.txt
# 3rd try: directly configure pip. Works, but these values should not be set in the Dockerfile!
ONBUILD RUN pip install --index-url http://xx.xx.xx.xx:yyyyy --trusted-host xx.xx.xx.xx --no-cache-dir -r requirements.txt
ONBUILD COPY . /usr/src/app
我的pip.conf
非常简单,在Docker之外使用时有效:
[global]
timeout = 60
index-url = http://xx.xx.xx.xx:yyyyy
trusted-host = xx.xx.xx.xx
链接:
我有以下问题:
- 为什么
ENV
不起作用? - 为什么在
RUN
命令中显式设置变量不起作用? - 这些问题是与
ONBUILD
或者RUN
有关吗?
Docker version 1.11.2, build b9f10c9
。 - blueFastStep 2 : RUN echo ${PIP_CONFIG_FILE} ---> Running in a5fc69f16f32 pip.conf
- blueFastpip
应该看到它们吗?似乎它没有看到。 - blueFast