当前位置: 首页 > 知识库问答 >
问题:

docker高山jdk铬硒:无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败

陈琪
2023-03-14

>

  • 我的java应用程序在没有docker的本地ubuntu上正常工作:JDK 11、Spring Boot、Selenium 4.0.0-rc-1、Chromium 97.0.4692.99、ChromeDriver 96.0.4664.45

    当我用JDK 11、Spring Boot、Selenium 4.0.0-rc-1、Chrome93.0.4577.82、ChromeDriver 93.0.4577.63将java应用程序迁移到docker(alpine)时,它不工作(但应用程序在使用ubuntu和chrome的docker上运行良好-现在我必须将其迁移到alpine和chrome)

    我的java驱动程序片段代码(当然我有更多标准选项,如--head less等):

    String chromeDriverLinux = "./config/driver/chromedriver-linux/chromedriver";   // 
    here is file in target version (93.0.4577.63 for docker)
    final ChromeOptions options = new ChromeOptions();
    options.addArguments("--remote-debugging-port=9222");
    
    /* commented on non-docker version - i think it may be needed by docker version
    when i execute it on local non-docker ver i received error: 
    Caused by: java.util.concurrent.ExecutionException: 
    java.util.concurrent.TimeoutException: Request timeout to localhost/127.0.0.1:21933 
    after 180000 ms
    */ 
    options.addArguments("--remote-debugging-address=0.0.0.0");   
    
    options.setBinary("/usr/bin/chromium-browser");
    ChromiumDriver driver = null;
    driver = new ChromeDriver(options);     // here is exception
    

    应用程序异常日志:

    driver exception: 
    org.openqa.selenium.SessionNotCreatedException: Could not start a new session. 
    Possible causes are invalid address of the remote server or browser start-up failure.
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:565) ~ 
    [selenium-remote-driver-4.0.0-rc-1.jar!/:?]
    ...
    Caused by: org.openqa.selenium.WebDriverException: Driver server process died 
    prematurely.
    Build info: version: '4.0.0-rc-1', revision: 'bc5511cbda'
    System info: host: '5c0bff50d486', ip: '172.17.0.2', os.name: 'Linux', os.arch: 
    'amd64', os.version: '5.13.0-27-generic', java.version: '11.0.14'
    Driver info: driver.version: ChromeDriver
    

    pom.xml:

            <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>${selenium.version}</version>
        </dependency>
    
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
    
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>${selenium.version}</version>
        </dependency>
    
    
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-devtools</artifactId>
            <version>${selenium.version}</version>
        </dependency>
    

    Dockerfile文件:

    FROM azul/zulu-openjdk-alpine:11
    
    RUN addgroup -S spring && adduser -S spring -G spring
    RUN mkdir -p config/driver/chromedriver-linux
    RUN find config/driver/chromedriver-linux/ -type d -exec chmod 0777 {} \;
    RUN find config/driver/chromedriver-linux/ -type f -exec chmod 777 {} \;
    
    ADD config/ /config/
    RUN chmod 0777 /config/driver/chromedriver-linux/chromedriver
    
    RUN apk update && apk add --no-cache bash \
    alsa-lib \
    at-spi2-atk \
    atk \
    cairo \
    cups-libs \
    dbus-libs \
    eudev-libs \
    expat \
    flac \
    gdk-pixbuf \
    glib \
    libgcc \
    libjpeg-turbo \
    libpng \
    libwebp \
    libx11 \
    libxcomposite \
    libxdamage \
    libxext \
    libxfixes \
    tzdata \
    libexif \
    udev \
    xvfb \
    zlib-dev \
    chromium \
    chromium-chromedriver \
    && rm -rf /var/cache/apk/* \
    /usr/share/man \
    /tmp/*
    
    
    USER spring:spring
    
    ARG JAR_FILE=target/*.jar
    COPY ${JAR_FILE} bot-app.jar
    ENTRYPOINT ["java","-jar","/bot-app.jar"]
    EXPOSE 9223 9222
    

    运行dockerfile:

    sudo docker build --no-cache=True -t bot-image .
    

    运行容器:

    sudo docker network create app_bot_network
    sudo docker run --network app_bot_network -p 8080:8080 -p 4444:4444 -p 9223:9222 -p 6900:5900 -it --rm --name bot-container bot-image:latest
    

    在启动docker之前,我还关闭了防火墙和vpn。

    那么,错误是什么:SessionNotCreatedException:无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败?

    这是一个没有驱动程序问题的版本,带有docker端口、网络设置的sth?或者执行浏览器?

    当做

  • 共有1个答案

    曹理
    2023-03-14

    我花了一些时间在这方面,并找到了解决办法。

    我在我的java代码中从:

    String chromeDriverLinux = "./config/driver/chromedriver-linux/chromedriver";
    

    (我在这里复制了最相似的ChromeDriver 93.0.4577.63版本)

    收件人:

    String chromeDriverLinux = "/usr/bin/chromedriver";
    

    (这里我有与dockerfile apk 93.0.4577.82安装的浏览器完全相同的驱动程序版本)

    我有一个奇怪的错误异常,而不是驱动程序版本是其他浏览器版本

     类似资料: