Setup Selenium Grid With Docker

Docker is the most popular open source light weight container platform. It is used to install and run any prepackaged applications especially for selenium grid automation test. You can easily add Node to your automation test grid with one line command. Start container is very fast and cost less resources. Please learn what docker is and how to setup and run it first by reading “Docker Overview” if you do not familiar with it. Then you can continue reading how to use it to setup automation test grid quickly and easily.

How to install and run in windows?

Please read this article “Docker Overview” to learn how to install and run it.

How to use it to setup selenium grid 

To build an automation test grid we need a Hub and several Nodes. Hub is the center of the grid, it is responsible for accepting and forwarding requests to related Node. Nodes is responsible for executing the test script and send the test script execute result back to the Hub. Please read the linked articles to learn How to setup selenium grid and How to use selenium grid to run testing script .

Docker already provide a lot of packages that can install Hub, Chrome node and Firefox node etc. We can go to docker selenium repository to get the ones we need.

docker selenium packages list

Steps To Setup Hub

  1. Execute command “docker pull selenium/hub” to get selenium Hub from official repository.
    download selenium hub from docker repository
  2. Execute command “docker run -d –name selenium-grid-hub selenium/hub” to start the Hub.

    You can also use “docker run -d -p 8888:4444 –name selenium-grid-hub selenium/hub” to map a physical machine’s port to the Hub container listening port.

    -d means detached. If you specify this parameter then the container will run at the background as a daemon.

    -p means map a local(physical host machine) port to the container port.
    -p 8888:4444 means you can use http://docker_machine_ip:8888/grid to access the container’s web console

    If you can not access your web console now, that maybe port mapping issue, please read step 4, there is how to change the mapping port number.

    Run “docker ps -a” to list all the containers with it’s status.

    run selenium grid hub in docker

  3. After the Hub container start up. Browse following url to see the container’s web console.
    selenium Hub web console run in docker container
    Please notice the ip address, it is just the docker machine’s ip. When you start the terminal, the docker machine’s ip will be shown at the first line of text in green color.
    docker machine's ip
  4. There is also a GUI program that can manage and change local port map. Click Kitematic icon in the desktop or startup menu.
    start docker windows gui
    When Kitematic start up. Left panel is the list of containers, right panel is the detail information for each selected container.
    container management guiSteps to change mapping port number:
    1. Select on container in left panel.
    2. Click Settings tab in the right panel.
    2. Click “Hostname / Ports” tab in right panel.
    3. Change port number in the “Configure ports” area.

  5. Use “docker stop container_name” to stop a container. In below picture, there are two containers one is running and the other is stopped.
    stop selenium hub in docker
  6. “docker logs container_name” is used to list all the configuration information for a container.
    list configuration data for selenium hub
    If the last line text is “Selenium Grid hub is up and running” in logs that means the Hub is running and ready for Nodes to register.

Steps To Setup Nodes

  1. Execute “docker pull selenium/node-chrome” to get a Chrome Node.
  2. Execute “docker pull selenium/node-firefox” to get a Firefox Node.
    download and install selenium chrome and firefox node container from docker repository
  3. Execute
    “docker run -d –link selenium-grid-hub:hub selenium/node-chrome”,
    “docker run -d –link selenium-grid-hub:hub selenium/node-firefox”
    to link the two Nodes to the Hub.

    After execute above command, two new Nodes has been added in the left panel list. Click one new added Node, Click “Settings —> General” in right panel. Change Node name in the container info area.
    change docker container selenium node name

  4. Now input url http://your_docker_machine_ip:4444/grid/console in web browser, you will find there has two Nodes added in the web console.
    selenium Hub web console after add tow Nodes
  5. Run “docker ps -a” to see all the containers installed in the machine. One Hub and Tow Nodes.
    all docker containers one selenium grid hub and two nodes

Install debug Nodes to watch test browser execution

Now the grid is ready for use, there has one Hub and 2 Nodes in the grid. But if we want to watch the browser action when test execute, we need to add below debug Nodes.

  1. Run “docker pull selenium/node-firefox-debug” to add Firefox debug Node.
  2. Run “docker pull selenium/node-chrome-debug” to add Chrome debug Node.
  3. Run
    “docker run -d —link selenium-grid-hub:hub selenium/node-chrome-debug”,
    “docker run -d —link selenium-grid-hub:hub selenium/node-firefox-debug”
    to link debug Nodes to Hub.
  4. Run “docker ps -a” to list all the containers. You can see there has two new browser debug Nodes with random name in below picture. The two debug Nodes are all listen on port 5900 in their container.
    new added chrome debug node and firefox debug node container in docker
  5. Change the Node’s random name in Kitematic.
    change selenium grid chrome debug Node name in docker
  6. Change physical machine port(container expose port) to map container port for each debug Node. In this example i change chrome-debug Node physical mapping port to 5901, and firefox-debug Node physical mapping port to 5900.
    change physical machine mapping port to browser debug node
  7. Download VNC viewer for your operating platform. Start VNC viewer.
  8. Click “File —> New connection” to connect to the chrome-debug Node in grid.
    create a new connection in vnc viewer
  9. Select one container in left panel list then click “Home” tab in right panel, copy the chrome-debug Node access url from Kitematic as below.
    get chrome debug node access url
  10. Paste above debug Node access url to vnc server input box in VCN new connection dialog.
    create vnc new connection dialog
  11. Click OK to save the connection. Double click the connection icon to connect to it.
    connect to chrome debug node in vnc viewer
  12. Input VCN viewer connection password, the default password is “secret”.
    input vnc connection password
  13. Then you connect to the chrome debug Node success and you can see the chrome web browser running when you run test cases scripts in this Node.
0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Oldest Most Voted
Inline Feedbacks
View all comments
Padmaja Kanade
Padmaja Kanade

Great article. I am also using the selenium grid on the similar lines. However when i try to execute the scripts on firefox, i get below error, how can I resolve this? Thanks much

org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessions.
Active sessions are[ext. key 6e05620b-0817-4355-8c30-15b54fe333b5, ext. key 5a97cdc6-12f5-4fd7-971c-1c6e67705530]
Command duration or timeout: 12 milliseconds
Build info: version: ‘2.53.1’, revision: ‘a36b8b1cd5757287168e54b817830adce9b0158d’, time: ‘2016-06-30 19:26:09’
System info: host: ‘AXEW0313’, ip: ‘’, ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_91’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{capabilities={moz:profile=/tmp/rust_mozprofile.NB8HAeRqNlg9, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, moz:headless=false, moz:accessibilityChecks=false, webdriver.remote.sessionid=5a97cdc6-12f5-4fd7-971c-1c6e67705530, acceptInsecureCerts=false, browserVersion=58.0.2, platformVersion=4.9.49-moby, moz:processID=434, browserName=firefox, platformName=linux, moz:webdriverClick=true}, sessionId=5a97cdc6-12f5-4fd7-971c-1c6e67705530, platform=ANY}]
Session ID: null

Reply to  Padmaja Kanade

I think you can change your Firefox browser version to make it stable with your current selenium jar library.



Would love your thoughts, please comment.x