【问题标题】:Trying to install selenium python3 package on docker image尝试在 docker 映像上安装 selenium python3 包
【发布时间】:2018-06-06 09:58:24
【问题描述】:

我尝试使用 selenium python 包重新构建 docker 映像,但未成功。我不确定如何继续。

这是我的 dockerfile:

FROM selenium/standalone-chrome:latest
WORKDIR /usr/local/bin
RUN sudo apt-get update
RUN sudo apt-get install software-properties-common
RUN sudo apt-add-repository universe
RUN sudo apt-get install python-pip
RUN pip3 install -r requirements.txt
RUN pip3 install .
RUN pip3 install -e .
COPY ./* ./

我很确定是我的 dockerfile 出错了,但是在尝试了各种安装 pip 的方法后,我画了一个空白。

无论如何我都会打电话给: docker build -t webdriver .

输出如下:

Sending build context to Docker daemon  4.608kB
Step 1/10 : FROM selenium/standalone-chrome:latest
 ---> 11258d1f9aba
Step 2/10 : WORKDIR /usr/local/bin
 ---> Using cache
 ---> 9297517083f6
Step 3/10 : RUN sudo apt-get update
 ---> Using cache
 ---> f9004a85fc1a
Step 4/10 : RUN sudo apt-get install software-properties-common
 ---> Running in bb2336c4ae46
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  apt-utils cron gir1.2-glib-2.0 iso-codes libapt-inst2.0 libcurl3-gnutls
  libgirepository-1.0-1 librtmp1 python-apt-common python3-apt python3-dbus
  python3-gi python3-pycurl python3-software-properties unattended-upgrades
  xz-utils
Suggested packages:
  anacron logrotate checksecurity exim4 | postfix | mail-transport-agent
  isoquery python3-apt-dbg python-apt-doc python-dbus-doc python3-dbus-dbg
  libcurl4-gnutls-dev python-pycurl-doc python3-pycurl-dbg bsd-mailx
  mail-transport-agent
The following NEW packages will be installed:
  apt-utils cron gir1.2-glib-2.0 iso-codes libapt-inst2.0 libcurl3-gnutls
  libgirepository-1.0-1 librtmp1 python-apt-common python3-apt python3-dbus
  python3-gi python3-pycurl python3-software-properties
  software-properties-common unattended-upgrades xz-utils
0 upgraded, 17 newly installed, 0 to remove and 5 not upgraded.
Need to get 3615 kB of archives.
After this operation, 22.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command '/bin/sh -c sudo apt-get install software-properties-common' returned a non-zero code: 1

我猜“你想继续吗?[Y/n] 中止。”需要回答“Y”,但我不知道该怎么做。我怀疑我错过了更多。

不用说我的 python 脚本仍然无法运行,因为它需要 selenium:

Traceback (most recent call last):
  File "web-test.py", line 3, in <module>
    from selenium import webdriver

谁能告诉我哪里出错了?

【问题讨论】:

  • 尝试使用-y 标志和sudo apt-get install。本质上,sudo apt-get install -y software-properties-common。这将假定所有使用apt-get 的安装调用都是肯定的。
  • @Abdou 感谢您的意见 - 这让我更进一步。我现在已经发现了我将尝试解决的包依赖问题。
  • 什么样的依赖问题? python 还是操作系统包?

标签: python-3.x docker selenium-webdriver pip dockerfile


【解决方案1】:

您已正确识别错误。您需要回答问题:Do you want to continue? [Y/n]Y 并继续。因此,如下更改您的 docker 文件并添加标志 -y

FROM selenium/standalone-chrome:latest
WORKDIR /usr/local/bin
RUN sudo apt-get -y update
RUN sudo apt-get install -y software-properties-common
RUN sudo apt-add-repository -y universe
RUN sudo apt-get install -y python3-pip
RUN pip3 install -r requirements.txt
RUN pip3 install .
RUN pip3 install -e .
COPY ./* ./

-y 标志可用于为所有 apt 安装假定 YES。您需要添加-y 标志,因为docker build 命令不能在交互模式下运行。因此,构建过程中的所有交互都必须添加到Dockerfile。 (Read this answer)

由于您要使用pip3,您需要正确安装它。您正在尝试安装pip2。我已经相应地更新了你的 docker 文件。您需要使用以下命令安装 pip3。

RUN sudo apt-get install -y python3-pip

【讨论】:

    【解决方案2】:

    你的 Dockerfile 中有几样东西:

    • 避免安装或使用 sudo,因为它具有不可预测的 TTY 和可能导致问题的信号转发行为。可以参考Dockerfile Best Practice
    RUN sudo apt-get update
    RUN sudo apt-get install software-properties-common
    RUN sudo apt-add-repository universe
    RUN sudo apt-get install python-pip
    
    • 消息
    Need to get 3615 kB of archives.
    After this operation, 22.6 MB of additional disk space will be used.
    Do you want to continue? [Y/n] Abort.
    The command '/bin/sh -c sudo apt-get install software-properties-common' returned a non-zero code: 1
    

    您需要在上面的 Docker 命令中添加标志 -y,以便在 Docker 构建过程中,它可以自动为您说 Yes

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-08
      • 2020-11-08
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多