当前位置: 首页 > 面试题库 >

Docker Container无法访问本地主机端口4444。为什么?

司空海荣
2023-03-14
问题内容

我将一个应用程序容器化,该应用程序是自动selenium测试的测试驱动程序。Selenium服务器(也称为Selenium
Hub)在localhost:4444下的另一个Container和Firefox Node中运行。但是我的应用程序无法达到它:

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)

我通过docker-compose启动了这些容器:

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-compose中有一个错误,但我无法弄清楚。请帮忙!顺便说一句:我正在Windows 7上运行,并将Docker与Vagrant
VM配合使用。在我的Vagrantfile中,我将端口4444和9005映射到了主机系统。如果打开本地浏览器并访问localhost:4444,则可以看到selenium网格控制台。为什么从我的应用程序容器中不起作用?


问题答案:

在您的应用程序容器中localhost是指当前容器。因此,您需要改用服务名称。您的情况是hub

所以连接到 hub:4444



 类似资料:
  • 我封装了一个应用程序,它是自动化Selenium测试的测试驱动程序。Selenium服务器(也称为Selenium Hub)运行在另一个容器中,以及本地主机4444下的Firefox节点。但我的应用程序无法访问它: 我通过docker-comush启动了这些容器: 我猜我的docker作文有错,但我想不出来。请帮忙!顺便说一句:我在Windows 7上运行,使用Docker和一个流浪的虚拟机。在我

  • 在ubunutu 14.04上安装tomcat7,使用 sudo apt-get install tomcat7 正在启动Tomcat servlet引擎tomcat7[OK] 但是我在本地主机上没有得到任何东西:8080 我也尝试更改默认端口,但不起作用。

  • 2017-05-20 15:23:31+0200:env:{“rack.version”=>[1,3],“rack.errors”=>#>,“rack.multithread”=>true,“rack.multiprocess”=>false,“rack.run_once”=>false,“script_name”=>>“query_string”=>>“http/1.1”,“server_sof

  • 我正在windows 8.1的笔记本电脑上使用Xampp localhost并试图通过我的手机访问它,我打开CMD并键入ipconfig和IPV4地址是192.168.1.3 我通过笔记本电脑打开它,它正常显示xampp文件夹,但当我将ip放入移动浏览器时,它什么也不给我(此网页不可用-ERR_CONNECTION_TIMED_OUT) 那么我怎样才能从我的android设备访问Xampp呢? 我

  • 我正在尝试改编Spring Boot网站上的REST控制器示例。不幸的是,当我试图访问URL时,出现了以下错误。 POM: 启动程序-应用程序: Rest控制器: null 我还可以做什么来通过URL访问该方法?