Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java dockerClient.createContainerCMD不';t将Selenium节点链接到集线器_Java_Selenium_Docker - Fatal编程技术网

Java dockerClient.createContainerCMD不';t将Selenium节点链接到集线器

Java dockerClient.createContainerCMD不';t将Selenium节点链接到集线器,java,selenium,docker,Java,Selenium,Docker,我试图用java Docker lib启动Selenium节点Docker容器,结果节点未链接到中心 container=dockerClient.createContainerCmd(图像) .withExposedPorts(exposedPort) .withHostConfig(新的HostConfig().withPortBindings(绑定)) .withName(姓名) .withEnv(“集线器主机=硒集线器”) .withEnv(“集线器端口=4444”) .exec();

我试图用
java Docker lib
启动Selenium节点Docker容器,结果节点未链接到中心

container=dockerClient.createContainerCmd(图像)
.withExposedPorts(exposedPort)
.withHostConfig(新的HostConfig().withPortBindings(绑定))
.withName(姓名)
.withEnv(“集线器主机=硒集线器”)
.withEnv(“集线器端口=4444”)
.exec();
dockerClient.startContainerCmd(container.getId()).exec();
我试着模仿我的docker作曲,就像这样:

version: '3'
services:
    selenium-hub:
            restart: always
            image: selenium/hub:latest
            ports:
              - 4444:4444

    chrome:
            restart: always
            image : selenium/node-chrome-debug:latest
            ports:
              - 6001:5900
            depends_on:
              - selenium-hub
            environment:
              - HUB_HOST=selenium-hub
              - HUB_PORT=4444
            links:
              - selenium-hub:hub
因此,我认为下面应该包括docker compose中的
HUB\u主机
HUB\u端口

.withEnv("HUB_HOST=selenium-hub")
.withEnv("HUB_PORT=4444")

但是,我不知道什么应该是依赖部分的java等价物。

首先,如果您使用的是docker compose,而不使用链接
selenium-hub:hub
,因此您最好使用别名
hub

("HUB_HOST=hub")
您还可以删除ENV,您可以直接使用
hub
主机

在docker compose中,容器可以引用另一个名为容器的容器,无需内衬

我还假设您是从同一个docker compose运行selenium hub

chrome:
        restart: always
        image : selenium/node-chrome-debug:latest
        ports:
          - 6001:5900
        depends_on:
          - selenium-hub
        environment:
          - HUB_HOST=selenium-hub
          - HUB_PORT=4444