在dockerfile中自定义ONBUILD环境

我稍微修改了这个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 

链接:

  • Dockerfile的ENV 在这里被logging
  • 这里loggingpipconfiguration

我有以下问题:

  • 为什么ENV不工作?
  • 为什么RUN命令中variables的显式设置不起作用?
  • 那些ONBUILD问题,或者是RUN

ONBUILD指令为图像添加一个触发器指令,稍后将该图像用作另一个构build的基础。

从文档 :

在1.4之前, ONBUILD指令不支持环境variables,即使与上面列出的任何指令结合使用。

使用docker工具1.4+,尝试(如问题15025所示 )

 ONBUILD ENV PIP_CONFIG_FILE pip.conf