How to start selenium hub and one linked node via docker-compose instead of using docker?

I can start a selenium hub image via:

docker run --rm=true -P -p 4444:4444  --name selenium-hub selenium/hub

and add a firefox worker via:

  • How to add an image to an organization in Docker Hub ?
  • Docker commands via php shell_exec
  • Add file to jenkins workspace with docker
  • How to give Dockerfile input parameters from docker run command
  • How do I create docker image from an existing CentOS?
  • Docker MYSQL '[2002] Connection refused'
  • docker run --rm=true --link selenium-hub:hub selenium/node-firefox
    

    Going on http://localhost:4444/grid/console then will show the grid just fine.

    I don’t want to use docker each time but have the same setup via docker-compose.

    Hence, I thought I could just do this in my docker-compose.yml:

    selenium_hub:
        image: selenium/hub
        ports: ["4444:4444"]
        links:
            - selenium_firefox_worker
    selenium_firefox_worker:
        image: selenium/node-firefox
    

    Yet after running docker-compose up I get the message:

    selenium_firefox_node_1 | Not linked with a running Hub container
    selenium_firefox_node_1 exited with code 1
    

    and hence the grid doesn’t show any node.

    I thought that I may be doing the linking in the wrong order, yet even:

    selenium_hub:
        image: selenium/hub
        ports: ["4444:4444"]
    selenium_firefox_node:
        image: selenium/node-firefox
        links:
            - selenium_hub
    

    yields in the same error.

    What am I doing wrong?

  • What does |1 mean in Docker history
  • docker exec wrong with remote docker host in Jenkins
  • Share Existing Host Directory with Docker Container?
  • Deploying Docker image to Kubernetes
  • malformed HTTP response with docker private registry (v2) behind an nginx proxy
  • Can one use python 3.5 in a docker container based out of the TensorFlow docker image?
  • 3 Solutions collect form web for “How to start selenium hub and one linked node via docker-compose instead of using docker?”

    selenium_hub:
        image: selenium/hub
        ports: ["4444:4444"]
    selenium_firefox_node:
        image: selenium/node-firefox
        links:
            - "selenium_hub:hub"
    

    While k0pernikus’ answer does work, I just wanted to elaborate on the reason why it was failing.

    The node containers expect to connect to a hub which is resolvable as simply:

    hub
    

    rather than in their example where it will be resolvable as:

    selenium_hub
    

    Stumbling across this tutorial, there was this syntax provided. And even though it’s similar to one of my approaches, it worked.

    hub:
      image: selenium/hub
      ports:
        - "4444:4444"
    firefox:
      image: selenium/node-firefox
      links:
        - hub
    chrome:
      image: selenium/node-chrome
      links:
        - hub
    

    It’s seems to be something about the naming, yet am not sure.

    As a side note, if using docker-compose version 2 format you have to specify a couple env variables, otherwise the node will not connect to the hub:

    version: '2'
    services:
        hub:
            image: selenium/hub
            ports:
                - "4444:4444"
    
        firefox:
            image: selenium/node-firefox
            environment:
                HUB_PORT_4444_TCP_ADDR: hub
                HUB_PORT_4444_TCP_PORT: 4444
            links:
                - hub
    

    Credits:
    Containers are not linked with docker-compose version 2

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.