代码之家  ›  专栏  ›  技术社区  ›  Timo

Docker容器无法到达本地主机端口4444。为什么?

  •  0
  • Timo  · 技术社区  · 8 年前

    我封装了一个应用程序,它是自动化Selenium测试的测试驱动程序。Selenium服务器(也称为Selenium Hub)运行在另一个容器中,以及本地主机4444下的Firefox节点中。

    Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
    System info: host: '10d3b5fd1010', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-4-amd64', java.version: '1.8.0_11            1'
    Driver info: driver.version: RemoteWebDriver
            at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
            at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
            at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
            at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
            at de.services.impl.TestSetupFactory.getWebDriver(TestSetupFactory.java:408)
            at de.services.impl.TestSetupFactory.getSeleniumService(TestSetupFactory.java:279)
            at de.services.impl.AutomationServiceImpl.executeTests(AutomationServiceImpl.java:220)
            at de.start.Start.main(Start.java:25)
    Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:4444 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: C            onnection refused (Connection refused)
            at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
            at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)

    version: '2'
    services:
      hub:
        image: selgrid:1.1
        ports:
          - "4444:4444"
    
      firefox:
        #pull latest from docker hub
        image: selenium/node-firefox
        volumes:
          - /dev/urandom:/dev/random
        depends_on:
          - hub
        environment:
          - HUB_PORT_4444_TCP_ADDR=hub
          - HUB_PORT_4444_TCP_PORT=4444
      testautomation:
        #run testautomation app
        image: volumetest
        links:
          - "hub"
        ports:
          - "9005:9005"

    我想我的docker作文有错,但我想不出来。请帮忙! 顺便说一句:我在Windows 7上运行,使用Docker和一个Vagrant VM。在我的Vagrantfile中,我将端口4444和9005映射到主机系统。如果打开本地浏览器,找到localhost:4444,我可以看到selenium网格控制台。为什么它在我的应用程序容器中无法工作?

    3 回复  |  直到 8 年前
        1
  •  5
  •   Tarun Lalwani    8 年前

    localhost hub

    所以连接到 hub:4444

        2
  •  0
  •   Haritha Hari    8 年前

    这是我得到的日志

    Connect to localhost:4444 [localhost/127.0.0.1] failed: Connection refused
    
    org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

    下面是docker compose yml文件的外观:

    version: '2'
    services:
      seleniumhub:
        image: selenium/hub
        ports:
          - 4444:4444
      firefoxnode:
        image: selenium/node-firefox-debug
        ports:
          - 5900
        environment:
            - HUB_PORT_4444_TCP_ADDR=seleniumhub
            - HUB_PORT_4444_TCP_PORT=4444
      webdrivertests:
        image: vodqa/gridtests
        volumes:
          - ./temp:/usr/src/app/target
        environment:
            - HUB_PORT_4444_TCP_ADDR=seleniumhub
            - HUB_PORT_4444_TCP_PORT=4444
        command: bash -c "cd /usr/src/app && mvn test"    

    new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),desiredCapabilitiesff   );
        3
  •  0
  •   Scott Cooper    4 年前

    services:   
        web:
            build:
                context: ./web
            links:
                - selenium
            ports:
                - "443:443"
    

    await new Builder()
    .setChromeOptions(options)
    .forBrowser("chrome")
    .usingServer("http://selenium:4444/wd/hub/")
    .build();
    
    推荐文章