[英]Trying to install selenium python3 package on docker image
我嘗試重新構建一個帶有 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”,但我不知道該怎么做。 我懷疑我錯過了更多。
不用說,我的 python 腳本仍然無法運行,因為它需要 selenium:
Traceback (most recent call last):
File "web-test.py", line 3, in <module>
from selenium import webdriver
誰能告訴我我哪里出錯了?
您已正確識別錯誤。 你需要回答這個問題: Do you want to continue? [Y/n]
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
。 (閱讀這個答案)
由於您要使用pip3
您需要正確安裝它。 您正在嘗試安裝pip2
。 我已經相應地更新了您的 docker 文件。 您需要使用以下命令來安裝 pip3。
RUN sudo apt-get install -y python3-pip
您的 Dockerfile 中有幾件事:
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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.