Docker 映像错误“服务 chromedriver 意外退出。状态代码为:127”

时间:2021-03-06 12:28:28

标签: selenium-webdriver selenium-chromedriver dockerfile

FROM python:3.7
WORKDIR /opt

RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb || apt-get install -yf
RUN rm /chrome.deb


ENV CHROMEDRIVER_VERSION 89.0.4389.23
ENV CHROMEDRIVER_DIR /chromedriver
RUN mkdir -p $CHROMEDRIVER_DIR

# Download and install Chromedriver
RUN wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR
ENV PATH $CHROMEDRIVER_DIR:$PATH
RUN apt-get update
COPY .  .

RUN pip3 install -r requirements.txt

CMD ["python3","code.py"]

代码.py

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

try:
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    driver = webdriver.Chrome(options=chrome_options)
    driver.get('google.com')
    print(f'{driver.page_source}')
except Exception as e:
    print(f'111111111 Exception: {e}')

try:
    options = webdriver.ChromeOptions()
    options.headless = True
    driver = webdriver.Chrome(options=options)
    driver.get('google.com')
    print(f'{driver.page_source}')
except Exception as e:
    print(f'222222 Exception: {e}')
print(f'h')

要求.txt

selenium

当我构建这个图像时,它构建得很好,但在运行图像时抛出以下错误

Service chromedriver unexpectedly exited. Status code was: 127

任何想法,我在 Dockerfile 中做错的地方。我尝试了其他可用的帖子,但没有任何效果。 我的机器操作系统是 Mac catalina 并试图为远程主机配置代码,但这甚至在我的本地系统上也不起作用。 这是我有另一个操作系统并配置另一个的问题吗

我也尝试了 this 个帖子,但没有任何效果

0 个答案:

没有答案