Why is it necessary this line to work with Selenium and Docker Swarm?

4/10/2018

Following Kubernetes Selenium example, I got the Grid working without any issue. However, I rather use Docker Swarm, so I translated k8s files to a docker-compose.yml.

version: '3.6'

services:
  hub:
    image: selenium/hub:3.11
    ports:
      - "4444:4444"

  chrome:
    image: selenium/node-chrome:3.11
    environment:
      HUB_PORT_4444_TCP_ADDR: hub
      HUB_PORT_4444_TCP_PORT: 4444

  firefox:
    image: selenium/node-firefox:3.11
    environment:
      HUB_PORT_4444_TCP_ADDR: hub
      HUB_PORT_4444_TCP_PORT: 4444

The stack was deployed and all containers were running. However, I could only access the main page of the Grid (http://localhost:4444). If I tried to access the console (http://localhost:4444/grid/console), the page never loaded, in fact, checking with the browser's dev tools, there wasn't even a request to such resource in the network tab.

Tried in different computers, the same... so something odd was happening.

After searching for a few minutes for selenium grid docker swarm, I found some outdated tutorials which also added entrypoint: bash -c 'SE_OPTS="-host $HOSTNAME" /opt/bin/entry_point.sh' to the chrome and firefox containers. So did I, and everything started to work without any issue, like in Kubernetes.

So my question is, why is that line necessary so that the Grid can work. And why is it not needed for k8s?

-- Ay0
docker
kubernetes
selenium

1 Answer

4/11/2018

You can find an explanation in the other StackOverflow question.

In short:

This is because the containers have two IP addresses in Swarm Mode and the nodes are picking up the wrong address and advertising that to the hub. This change will have the nodes advertise their hostname so the hub can find the nodes by DNS instead.

In Kubernetes, a container in a pod has only one IP address, that's why you do not need to set that variable, your application is always picking a right IP.

-- Anton Kostenko
Source: StackOverflow