2021年4月29日星期四

Selenium docker crashes on Windows (unknown error: DevToolsActivePort file doesn't exist)

Summary: works on the mac but not on windows. Please note: This is not a duplicate of other similar issues, I have researched this for more than a day on SO and elsewhere.

I built a super simple script which executes 2 dockers containers: one with chrome browser, chromedriver and the other with the test. It runs fine on Linux, but when I launch the containers on Windows I'm getting;

root@4ba2401510ed:/wdir# ../usr/bin/php7.1 chromeTest.php  PHP Fatal error:  Uncaught Facebook\WebDriver\Exception\UnknownErrorException: unknown error: Chrome failed to start: crashed.    (unknown error: DevToolsActivePort file doesn't exist)    (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has   crashed.)  Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'  System info: host: '5cc73cb1d7df', ip: '172.18.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.72-microsoft-standard-WSL2', java.version: '1.8.0_282'  Driver info: driver.version: unknown  remote stacktrace: #0 0x564b66a6ce89 <unknown>   in /wdir/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:139  Stack trace:  #0 /wdir/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php(371): Facebook\WebDriver\Exception\WebDriverException::throwException('unknown error', 'unknown error: ...', Array)  #1 /wdir/vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php(135): Facebook\WebDriver\Rem in /wdir/vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php on line 139  

Has anyone seen this before? It looks like Docker just behaves differently on Windows and makes the Chrome inside the docker container crash..

I tried proposed solutions such as adding --headless, --sandbox, etc. but it really seems to be something with the way docker works on windows.

Yaml file

version: '3.4'    services:      # Contains the chrome browser, chromedriver    chrome:      image: selenium/standalone-chrome-debug      volumes:        - /dev/shm:/dev/shm      ports:        - "4444:4444"        - "5900:5900"      # Contains PHP webdriver library    php7:      build:        context: .        dockerfile: ./Dockerfile      volumes:        - .:/wdir/      depends_on:        - chrome      command: tail -F anything  

Dockerfile

FROM scratch  ADD ubuntu-xenial-core-cloudimg-amd64-root.tar.gz /  ADD start.sh /  # Chromium DEB file  #ADD google-chrome-stable_90.0.4430.85-1_amd64.deb /  #ADD chromedriver /  # ADD firefox_88.0-1_i386.deb /    # a few minor docker-specific tweaks  # see https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap  RUN set -xe \    \  # https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L40-L48    && echo '#!/bin/sh' > /usr/sbin/policy-rc.d \    && echo 'exit 101' >> /usr/sbin/policy-rc.d \    && chmod +x /usr/sbin/policy-rc.d \    \  # https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L54-L56    && dpkg-divert --local --rename --add /sbin/initctl \    && cp -a /usr/sbin/policy-rc.d /sbin/initctl \    && sed -i 's/^exit.*/exit 0/' /sbin/initctl \    \  # https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L71-L78    && echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \    \  # https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L85-L105    && echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \    && echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \    && echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \    \  # https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L109-L115    && echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \    \  # https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L118-L130    && echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes \    \  # https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L134-L151    && echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests    # this forces "apt-get update" in dependent images, which is also good  # (see also https://bugs.launchpad.net/cloud-images/+bug/1699913)    # make systemd-detect-virt return "docker"  # See: https://github.com/systemd/systemd/blob/aa0c34279ee40bce2f9681b496922dedbadfca19/src/basic/virt.c#L434  RUN mkdir -p /run/systemd && echo 'docker' > /run/systemd/container    # Install updates  RUN apt-get update -y && apt-get install -y software-properties-common language-pack-en-base \  \  # Install Java  -y default-jre \  \  # Install snapd  -y snapd \  \   # Install wget  -y wget \  -y lsof    # Clean up  RUN rm -rf /var/lib/apt/lists/*    # Get the PHP library  RUN LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php    RUN apt-get -y update && apt-get install -y \      php7.1 \      php7.1-pgsql \      php-pear \      php7.1-curl \      php7.1-sqlite3 \      php7.1-xml \      php7.1-bcmath \      php7.1-zip \      php7.1-mbstring \      php-xdebug \      php7.1-mysqli \      php-ast      # Define the working directory for this container  WORKDIR /wdir    # RUN chmod +x ./start.sh    CMD ["start.sh"]  
https://stackoverflow.com/questions/67294395/selenium-docker-crashes-on-windows-unknown-error-devtoolsactiveport-file-doesn April 28, 2021 at 01:47PM

没有评论:

发表评论