Selenium node/chrome docker image and selenium/hub docker image in different host machines

I have a situation where i have to use the node/chrome and selenium/hub images in different host machines. However problem is although i am linking them in the ansible role as below:

- name: seleniumchromenode container
  docker:
    name: seleniumhubchromenode
    image: "{{ seleniumchromenode_image }}"
    state: "{{ 'started' }}"
    pull: always
    restart_policy: always
    links: seleniumhub:hub

It doesnt get linked , or in other words the hub is not discovering the node. Please let me know if linking works only when the hub and node are within the same host machine.

  • Jenkins in docker, workspace location
  • Running docker gitlab-runner with net=host option
  • Dockerfile: mkdir and COPY commands run fine but I can't see the directory and file
  • .Net Core can't use Add-migrations with Docker support
  • Possible to http clone repo to Docker Container?
  • Running and debugging tests in a Docker container
  • Docker: Unable to clone a github private rebo inside at run time
  • Unable to push image to docker hub
  • sudo docker build -t=“nisevi/static_web” is not working
  • Vagrant multi-machine with docker tries to create two boot2docker vms
  • Docker and Windows - Problems with SSH on default container
  • Use Docker.io without the build-in NAT function but with DHCP
  • 2 Solutions collect form web for “Selenium node/chrome docker image and selenium/hub docker image in different host machines”

    Links don’t work across machines. You can either specify the IP address/hostname and let it connect through that, or you can use Docker Swarm Mode to deploy your containers – that lets you do something very close to linking (it sets up a mesh network across the swarm nodes, so services can find each other).

    Simplest: just pass the hostname in Ansible.

    Below is what finally worked for me. Note that the SE_OPTS is necessary for the node to be able to link successfully to the hub that is on a different host.

    - name: seleniumchromenode container
      docker_container:
        name: seleniumhubchromenode
        image: "{{ seleniumchromenode_image }}"
        state: "{{ 'started' }}"
        pull: true
        restart_policy: always
        exposed_ports:
          - "{{seleniumnode_port}}"
        published_ports:
          - "{{seleniumnode_port}}:{{seleniumnode_port}}"
        env:
          HUB_PORT_4444_TCP_ADDR: "{{seleniumhub_host}}"
          HUB_PORT_4444_TCP_PORT: "{{seleniumhub_port}}"
          SE_OPTS: "-host {{seleniumnode_host}} -port {{seleniumnode_port}}"
          NODE_MAX_INSTANCES: "5"
          NODE_MAX_SESSION: "5"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.