托管VM添加到PATH

时间:2015-04-21 06:04:58

标签: google-app-engine selenium docker boot2docker

Google App Engine's Python runtime for Managed VMS中,我想安装Splinter(selenium)Chromedriver。根据Linux的文档,我在dockerfile中有以下内容:

# Dockerfile extending the generic Python image with application files for a
# single application.
FROM gcr.io/google_appengine/python-compat

RUN apt-get update && apt-get install -y apt-utils zip unzip wget

ADD requirements.txt /app/
RUN pip install -r requirements.txt

RUN cd $HOME/
RUN wget https://chromedriver.googlecode.com/files/chromedriver_linux64_20.0.1133.0.zip
RUN unzip chromedriver_linux64_20.0.1133.0.zip

RUN mkdir -p $HOME/bin
RUN mv chromedriver /bin
ENV PATH "$PATH:$HOME/bin"

ADD . /app

我无法让web应用程序使用chrome webdriver启动Splinter,因为它在PATH中找不到它。

  

WebDriverException:消息:'chromedriver'可执行文件需要为
  在路径中可用。请看看   http://docs.seleniumhq.org/download/#thirdPartyDrivers
  并阅读了   http://code.google.com/p/selenium/wiki/ChromeDriver

如果按预期运行docker exec -it <container id> chromedriver,则无效。

此外,在Python中打印的环境变量是:

➜  ~  docker exec -it f4d9541c4ba6 python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print os.environ
{'GAE_MODULE_NAME': 'parsers', 'API_HOST': '10.0.2.2', 'GAE_SERVER_PORT': '8082', 'MODULE_YAML_PATH': 'parsers.yaml', 'HOSTNAME': 'f4d9541c4ba6', 'SERVER_SOFTWARE': 'Development/2.0', 'GAE_MODULE_INSTANCE': '0', 'DEBIAN_FRONTEND': 'noninteractive', 'GAE_MINOR_VERSION': '580029170989395749', 'API_PORT': '59768', 'GAE_PARTITION': 'dev', 'GAE_LONG_APP_ID': 'utix-app', 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'GAE_MODULE_VERSION': 'parsers-0-0-1', 'HOME': '/root'}

使chromedriver成为PATH或其他解决方法的正确方法是什么?

非常感谢

1 个答案:

答案 0 :(得分:0)

您需要检查与该图片相关联的ENTRYPOINTCMD(在您发布的容器上执行docker inspect

如果图片设置为打开新的bash会话,则与运行该会话的帐户关联的profile.bashrc可能会重新定义$PATH,从而覆盖Dockerfile ENV PATH "$PATH:$HOME/bin"指令。

如果是这种情况,请确保profile.bashrc定义正确PATH更容易(使用COPY自定义.bashrc实例)修改ENV