Docker (已解决) 请教 selenium 分布式的 docker-compose.yml 编写语法错误

oly · 2018年04月10日 · 最后由 lyu 回复于 2018年04月10日 · 2347 次阅读

想创建 selenium grid 上的 hub 和五个 node 子节点. 其中 hub 是调度的服务,五个 node 需要注册到 hub 上去.
我的写法不对,麻烦小哥们帮我看看

docker-compose.yml
创建 selenium 的服务主节点

Hub:
  image: selenium/hub
  container_name: hub
  ports:
    - "5555:4444"
  volumes:
    - /opt/conf/:/mnt

创建子节点 (通过 links: - Hub) 关联注册到 hub 上.然而启动报错.错误信息在最下面< ERROR : Not linked with a running Hub container>

Firenode02:
  image: selenium/node-firefox-debug
  ports:
    - "5902:5901"
  environment:
    DBUS_SESSION_BUS_ADDRESS: /dev/null
    NODE_MAX_INSTANCES: 5
    NODE_MAX_SESSION: 5
    NODE_REGISTER_CYCLE: 5000
  links:
    - Hub
Firenode03:
  image: selenium/node-firefox-debug
  ports:
    - "5903:5901"
  environment:
    DBUS_SESSION_BUS_ADDRESS: /dev/null
    NODE_MAX_INSTANCES: 5
    NODE_MAX_SESSION: 5
    NODE_REGISTER_CYCLE: 5000
  links:
    - Hub

命令: vi docker-compose.yml

version: '2'
services:
  Hub:
    image: selenium/hub
    container_name: hub
    ports:
      - "5555:4444"
    volumes:
      - /opt/conf/:/mnt
  Firenode02:
    image: selenium/node-firefox-debug
    ports:
      - "5902:5901"
    environment:
      DBUS_SESSION_BUS_ADDRESS: /dev/null
      NODE_MAX_INSTANCES: 5
      NODE_MAX_SESSION: 5
      NODE_REGISTER_CYCLE: 5000
    links:
      - Hub
  Firenode03:
    image: selenium/node-firefox-debug
    ports:
      - "5903:5901"
    environment:
      DBUS_SESSION_BUS_ADDRESS: /dev/null
      NODE_MAX_INSTANCES: 5
      NODE_MAX_SESSION: 5
      NODE_REGISTER_CYCLE: 5000
    links:
      - Hub

命令:docker-compose -f docker-compose.yml up

异常输出

##docker@default:~/composetest$ docker-compose -f docker-compose.yml  up


hub is up-to-date
Starting composetest_Firenode03_1 ... done
Starting composetest_Firenode04_1 ... done
Starting composetest_Firenode02_1 ... done
Attaching to hub, composetest_Firenode03_1, composetest_Firenode02_1, composetest_Firenode04_1
Firenode03_1  | Not linked with a running Hub container
hub           | starting selenium hub with configuration:
hub           | {
hub           |   "port": 4444,
hub           |   "role": "hub",
hub           |   "maxSession": 5,
hub           |   "newSessionWaitTimeout": -1,
hub           |   "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
hub           |   "throwOnCapabilityNotPresent": true,
hub           |   "jettyMaxThreads": -1,
hub           |   "cleanUpCycle": 5000,
hub           |   "browserTimeout": 0,
hub           |   "timeout": 30,
hub           |   "debug": false
hub           | }
hub           | 18:11:08.444 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.11.0', revision: 'e59cfb3'
hub           | 18:11:08.476 INFO [GridLauncherV3$2.launch] - Launching Selenium Grid hub on port 4444
hub           | 2018-04-09 18:11:09.392:INFO::main: Logging initialized @7309ms to org.seleniumhq.jetty9.util.log.StdErrLog
hub           | 18:11:10.356 INFO [Hub.start] - Selenium Grid hub is up and running
hub           | 18:11:10.362 INFO [Hub.start] - Nodes should register to http://172.18.0.2:4444/grid/register/
hub           | 18:11:10.367 INFO [Hub.start] - Clients should connect to http://172.18.0.2:4444/wd/hub
hub           | 18:12:15.851 INFO [RequestHandler.process] - Got a request to create a new session: Capabilities {browserName: firefox, version: }
hub           | 18:12:15.863 INFO [RequestHandler.process] - Error forwarding the new session Empty pool of VM for setup Capabilities {browserName: firefox, version: }
hub           | org.openqa.grid.common.exception.GridException: Empty pool of VM for setup Capabilities {browserName: firefox, version: }
hub           |         at org.openqa.grid.internal.ProxySet.verifyAbilityToHandleDesiredCapabilities(ProxySet.java:146)
hub           |         at org.openqa.grid.internal.DefaultGridRegistry.addNewSessionRequest(DefaultGridRegistry.java:217)
hub           |         at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:111)
hub           |         at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:86)
hub           |         at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:70)
hub           |         at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
hub           |         at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
hub           |         at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:860)
hub           |         at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
hub           |         at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
composetest_Firenode03_1 exited with code 1


共收到 4 条回复 时间 点赞
oly #1 · 2018年04月10日 Author

学这个语法除了官方的https://docs.docker.com/compose/reference/overview/ 现在不想啃这个英文文档,有教程推荐?

具体不太懂,可以试一下换个端口 ? 我看 node 镜像的 docker file 是有这一句的 “EXPOSE 5900”,贴一下我能成功运行例子:

hub:
  image: selenium/hub
  ports:
    - 4444:4444
firefox:
  image: bgzhou/node-firefox-debug:v1
  ports:
    - 5901:5900
  links:
    - hub
chrome:
  image: bgzhou/node-chrome-debug:v1
  ports:
    - 5902:5900
  links:
    - hub
oly #3 · 2018年04月10日 Author
cookie 回复

多谢,我参考了你的,去掉了头部一些最后是如下的内容.下午试下并发的效果.

Hub:
  image: selenium/hub
  container_name: hub
  ports:
    - 5555:4444
  volumes:
    - /opt/conf/:/mnt
Firenode12:
  image: wywincl/node-firefox-debug
  ports:
    - 5912:5901
  environment:
    DBUS_SESSION_BUS_ADDRESS: /dev/null
    NODE_MAX_INSTANCES: 5
    NODE_MAX_SESSION: 5
    NODE_REGISTER_CYCLE: 5000
  links:
    - Hub
Firenode13:
  image: wywincl/node-firefox-debug
  ports:
    - 5913:5900
  environment:
    DBUS_SESSION_BUS_ADDRESS: /dev/null
    NODE_MAX_INSTANCES: 5
    NODE_MAX_SESSION: 5
    NODE_REGISTER_CYCLE: 5000
  links:
    - Hub

The solution was to remove the -role hub part and it should work.

oly 关闭了讨论 04月13日 15:24
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册