如何修复“未知的错误:Chrome无法启动:exception退出”在Docker中运行chrome?

我想用jenkinsjenkins实例中运行seleniumtesting。 为了testing这个,我使用下面的Dockerfile创build一个Dockerfile

 FROM python:2.7-slim WORKDIR /selenium ADD . /selenium # Install any needed packages specified in requirements.txt RUN pip install --trusted-host pypi.python.org -r requirements.txt # Install some basic stuff RUN apt-get update -qqy RUN apt-get install -y wget xvfb bzip2 zip unzip # Install all the chrome libraries... RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils # Set firefox version and installation directory through environment variables. ENV FIREFOX_VERSION 45.0 ENV FIREFOX_DIR /usr/bin/firefox ENV FIREFOX_FILENAME $FIREFOX_DIR/firefox.tar.bz2 # Download the firefox of specified version from Mozilla and untar it. RUN mkdir -p $FIREFOX_DIR RUN wget -q --continue --output-document $FIREFOX_FILENAME "https://ftp.mozilla.org/pub/firefox/releases/${FIREFOX_VERSION}/linux-x86_64/en-US/firefox-${FIREFOX_VERSION}.tar.bz2" RUN tar -xaf "$FIREFOX_FILENAME" --strip-components=1 --directory "$FIREFOX_DIR" # Prepend firefox dir to PATH ENV PATH $FIREFOX_DIR:$PATH # Install Chrome ENV LOCALEXE /usr/local/bin ENV CHROMEDRIVERZIP=chromedriver_linux64.zip ENV CHROMEDRIVER=chromedriver RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install RUN wget "http://chromedriver.storage.googleapis.com/2.33/${CHROMEDRIVERZIP}" RUN unzip ${CHROMEDRIVERZIP} RUN mv ${CHROMEDRIVER} ${LOCALEXE} # Prepare the output directories RUN mkdir -p /selenium/out RUN ln -sf /dev/stdout /selenium/out/out.log RUN ln -sf /dev/stderr /selenium/out/err.log RUN Xvfb :99 -ac -screen 0 1280x1024x16 & ENV DISPLAY :99 # Run app.py when the container launches CMD ["nosetests", "-s", "test1.py"] 

并在实际的testing文件( test1.py )中也有行

 from pyvirtualdisplay import Display display = Display(visible=0, size=(800, 800)) display.start() 

在创buildseleniumwebdriver之前,基于来自这里和这里和这里的build议。 但是,在创builddocker镜像并使用以下命令运行之后

 docker run --rm selenium1 docker run --rm -e DISPLAY=$DISPLAY selenium1 docker run --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix selenium1 

我总是得到以下错误:

 Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest self.test(*self.arg) File "/selenium/test1.py", line 43, in test_fac driver = webdriver.Chrome(chrome_options=chrome_options) File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__ desired_capabilities=desired_capabilities) File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__ self.start_session(desired_capabilities, browser_profile) File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute self.error_handler.check_response(response) File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.10.0-37-generic x86_64) 

如何解决它? 如何确保我可以在Docker容器中使用chrome (和firefox )进行seleniumtesting?

版本:

  • docker
  • selenium3.7.0
  • 鼻1.3.7
  • pyvirtualdisplay-0.2.1
  • xvfb 2:1.16.4-1 + deb8u2
  • chromedriver = 2.33.506092
  • Linux 4.10.0-37-generic x86_64
  • 谷歌浏览器:62.0.3202.89-1

您正在使用chromedriver=2.9.248304 selenium-3.7.0google-chrome: 62.0.3202.89-1

根据发行说明 ,使用此浏览器,您应该使用:

 ----------ChromeDriver v2.33 (2017-10-03)---------- Supports Chrome v60-62