【问题标题】:Connection refused error by Selenium webdriver when running firefox in a docker container在 docker 容器中运行 firefox 时,Selenium webdriver 的连接被拒绝错误
【发布时间】:2019-07-26 06:03:28
【问题描述】:

我正在尝试在使用 centos 作为基础映像的 docker 容器中使用 gecko 驱动程序 0.24.0 在 firefox 68.0.esr 上运行基本硒测试。网络驱动程序拒绝连接。

1. I tried downgrading the firefox and gecko driver(tried with firefox 60 and gecko driver 0.21.0)
2. The test runs fine outside the container in a centos linux machine.
3. I tired exposing all the ports of the docker container
4. I tried but couldn't restrict the  gecko driver to run on a dedicated port.

Docker 文件片段:

FROM centos:latest

# Install pre-requisites
RUN yum install -y \
        bzip2 \
        dbus-x11 \
        build-essential \
        libgl1-mesa-glx \
        gtk3
COPY firefox-68.0esr.tar.bz2 /tmp
RUN tar -xvjf /tmp/firefox-68.0esr.tar.bz2 -C /usr/share \
        && ln -s /usr/share/firefox/firefox /usr/bin/firefox

EXPOSE 1025-65535

docker 运行命令:

docker run --privileged -it --shm-size=2g --rm -u $(id -u):$(id -g) -v "  firefox

错误日志:

    1564119317051   geckodriver     INFO    geckodriver 0.21.0
    1564119317056   geckodriver     INFO    Listening on 127.0.0.1:27326
    1564119317288   mozrunner::runner       INFO    Running command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.BiPoRQ1CUTKA"
    1564119317290   geckodriver::marionette DEBUG   Waiting 60s to connect to browser on 127.0.0.1:40722
    *** You are running in headless mode.
    1564119377337   webdriver::server       DEBUG   <- 500 Internal Server Error {"value":{"error":"unknown error","message":"connection refused","stacktrace":""}}
    2019-07-26 05:36:17,381 [main] DEBUG freemarker.cache - Couldn't find template in cache for "index.ftl"("en", UTF-8, parsed); will try to load it.
    2019-07-26 05:36:17,382 [main] DEBUG freemarker.cache - TemplateLoader.findTemplateSource("index_en.ftl"): Not found
    2019-07-26 05:36:17,383 [main] DEBUG freemarker.cache - TemplateLoader.findTemplateSource("index.ftl"): Found
    2019-07-26 05:36:17,383 [main] DEBUG freemarker.cache - Loading template for "index.ftl"("en", UTF-8, parsed) from "jar:file:/var/maven/.m2/repository/com/aventstack/extentreports/3.1.5/extentreports-3.1.5.jar!/com/aventstack/extentreports/view/html-report/index.ftl"



    Caused by: org.openqa.selenium.WebDriverException: connection refused
    Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
    System info: host: '6919b4dea6cf', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-957.21.3.el7.x86_64', java.version: '1.8.0_212'
    Driver info: driver.version: FirefoxDriver

【问题讨论】:

标签: selenium docker firefox centos7 geckodriver


【解决方案1】:

我通过以 root 身份运行容器解决了这个问题,因为结果证明我为运行容器而创建的用户没有所需的权限。

【讨论】:

  • 这是一个经典的坏主意。不要以 root 身份运行您的容器。权限可以轻松升级以入侵主机。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-03
  • 2018-11-16
  • 1970-01-01
  • 1970-01-01
  • 2015-12-10
  • 2018-03-18
  • 2021-12-31
相关资源
最近更新 更多