如何在docker-compose中将公共端口分配给端口5900

时间:2017-04-01 15:11:10

标签: docker selenium-webdriver docker-compose selenium-grid

我有以下YAML文件:

seleniumhub:

image: selenium/hub

ports: 
 - 4444:4444

firefoxnode:

image: selenium/node-firefox-debug  

ports:
 - 4577

links: 
 - seleniumhub:hub 

expose: 
 - "5900"

chromenode:

image : selenium/node-chrome-debug

ports:
 - 4578

links:
 - seleniumhub:hub

expose: 
 - "5900"

docker ps:

time="2017-04-01T17:57:44+03:00" level=info msg="Unable to use system certificate pool: crypto/x509: system root pool is not available on Windows"

CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                               NAMES
9d2ccb193b54        selenium/node-firefox-debug   "/opt/bin/entry_po..."   6 seconds ago       Up 5 seconds        5900/tcp, 0.0.0.0:32785->4577/tcp   dockercompose_firefoxnode_1
4be6223fe043        selenium/node-chrome-debug    "/opt/bin/entry_po..."   6 seconds ago       Up 5 seconds        5900/tcp, 0.0.0.0:32784->4578/tcp   dockercompose_chromenode_1
7d95d3e73016        selenium/hub                  "/opt/bin/entry_po..."   7 seconds ago       Up 6 seconds        0.0.0.0:4444->4444/tcp              dockercompose_seleniumhub_1

但每当我在Docker快速启动终端中运行以下命令时:

docker port 9d2ccb193b54 5900

我得到了以下内容:

  

错误:没有为9d2ccb193b54发布公共端口'5900 / tcp'

我无法通过VNC连接到节点机器

2 个答案:

答案 0 :(得分:1)

firefoxnode尝试此配置:

image: selenium/node-firefox-debug  

ports:
 - 4577
 - 5900

links: 
 - seleniumhub:hub 

expose: 
 - "5900"

expose不会将端口发布到主机,只能访问链接的服务。它适用于容器间通信。 ports会将该端口暴露给主机。

答案 1 :(得分:0)

对于暴露端口,其语法为:

ports:
  - "host:container"

在你的情况下:

image: selenium/node-firefox-debug  

ports:
 - 4577
 - "5900:5900"

links: 
 - seleniumhub:hub 

此致