gpt4 book ai didi

docker - Selenium docker 在 Windows 上崩溃(未知错误 : DevToolsActivePort file doesn't exist)

转载 作者:行者123 更新时间:2023-12-05 04:50:23 25 4
gpt4 key购买 nike

总结:适用于 mac 但不适用于 windows。请注意:这不是其他类似问题的重复,我已经在 SO 和其他地方对此进行了超过一天的研究。

我构建了一个 super 简单的脚本,它执行 2 个 docker 容器:一个带有 chrome 浏览器、chromedriver,另一个带有测试。它在 Linux 上运行良好,但当我在 Windows 上启动容器时,我得到了;

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

有没有人见过这个?看起来 Docker 只是在 Windows 上表现不同,导致 Docker 容器内的 Chrome 崩溃。

我尝试了建议的解决方案,例如添加 --headless--sandbox 等,但这似乎确实与 docker 在 windows 上的工作方式有关。

yaml 文件

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

Docker文件

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"]

最佳答案

这可能是由于 windows 更新和 docker 镜像没有相应更新时发生的问题。尝试回滚到以前的版本可以修复它。

此外,尝试使用不同的 docker 镜像进行实验,例如

"selenium/standalone-chrome"

将有助于调试问题。

在 Windows WSL 更新之前工作的先前图像的示例

image: selenium/standalone-chrome:89.0.4389.90-chromedriver-89.0.4389.23-20210315

一些选项可能还需要在实例化驱动对象时进行调整,这里是一个工作示例

$options = new ChromeOptions();
$options->addArguments(["no-sandbox","headless", "disable-dev-shm-usage"]);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $options);
$driver = RemoteWebDriver::create($host, $capabilities);

关于docker - Selenium docker 在 Windows 上崩溃(未知错误 : DevToolsActivePort file doesn't exist),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67294395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com