Setting up Selenium GRID using Docker


Docker is a containerzation platform, it can be defined, as simple as BUILD, SHIP and RUN.

A container is a light-weight or a scaled down Virtual machine. This is what we are seeing elsewhere in the web. Let us deep dive a bit and compare the differences.

Analogy : Container Vs Virtual Machine

Source: Docker website.

Both are designed to provide an isolated environment in which to run an application. Additionally, the environment is represented as a binary artefact that can be moved between hosts.

The underlying architecture is completely different, easy way to interpret is by looking at the image below.
Screen Shot 2016-11-28 at 11.19.19 AM

Imagine a Virtual machine as a House and Docker container as an Apartment or an unit.

Houses (the VMs) are fully self-contained and offer protection from unwanted guests. They also each possess their own infrastructure –plumbing, heating, electrical, etc. Furthermore, in the vast majority of cases houses are all going to have at a minimum a bedroom, living area, bathroom, and kitchen.

Apartments (Docker containers) they are built around shared infrastructure. The apartment building (the server running the Docker daemon, otherwise known as a Docker host) offers shared plumbing, heating, electrical, etc. to each apartment. Additionally, apartments are offered in several different sizes – from studio to multi-bedroom penthouse. You’re only renting exactly what you need.

Docker is not a virtualization technology, it’s an application delivery technology.
Excellent isn’t it ? credit goes to the guys at Docker for this example. You can thank me for collating it here 🙂

How Docker is helping the Test Automation world ?
It helps by providing a seamless environment for Distributed testing. The moment we hear Distributed testing in Selenium world, Selenium Grid comes to our mind. Yes! In earlier days or still, a few companies have different VM’s hosted as a node and connected to a hub. This is costly. Hence people were choosing the Test on Cloud platforms like SauceLabs and Browserstack. Docker eliminates all those infra setup and cost benefits.

Now that, we saw how a VM and Docker container differs, Instead of each separate VM as a Node, each container in a Docker is considered as a Node. Imagine the possibilities. Scaling up the Nodes(Containers) are easy. SauceLabs and Browserstack are still different and have their own positives.

Let’s setup docker-selenium in our machine.


Step 1: Download Docker from

Step 2: Install as per your OS instructions.

Docker will be running as a daemon process and could be seen here on your mac system bar.
Screen Shot 2016-11-28 at 12.03.10 PM


Step 1: On your Terminal(Mac) type in docker –version it should print out version number.

Official Repository page:

The classic problem of dev and QA getting into a debate for a bug or a feature that may work fine in dev system but not in the QA system, all that problem shall be resolved with this Node containers.

Pull and then run the image are two basic things to be done with docker images.

Selenium Grid Standalone

Step 1: docker pull selenium/standalone-chrome-debug Likewise you can pull in all the images as you want.

Running a standalone machine without connecting to a hub, image names with description.
selenium/standalone-chrome: Selenium standalone with Chrome installed
selenium/standalone-firefox: Selenium standalone with Firefox installed
selenium/standalone-chrome-debug: Selenium standalone with Chrome installed and runs a VNC server
selenium/standalone-firefox-debug: Selenium standalone with Firefox installed and runs a VNC server

Step 2: docker run -d --name selenium -p 5900:5900 -p 4444:4444 selenium/standalone-chrome-debug
Screen Shot 2016-11-28 at 12.21.53 PM

You can view this standalone machine through your VNC viewer or Screen Sharing app on your Mac.

Step 3: docker ps -a on your screensharing app use localhost:5900 you will see a ubuntu logo 🙂 That’s it you are done and you can run a sample test and view in this machine.
Screen Shot 2016-11-28 at 12.39.41 PM

Selenium Grid with Hub and Node

Step 1: docker pull selenium/hub

Step 2: docker pull selenium/node-chrome-debug.

and few other images with the description as follows.
selenium/hub: Image for running a Selenium Grid Hub
selenium/node-chrome: Selenium node with Chrome installed, needs to be connected to a Selenium Grid Hub
selenium/node-firefox: Selenium node with Firefox installed, needs to be connected to a Selenium Grid Hub
selenium/node-chrome-debug: Selenium node with Chrome installed and runs a VNC server, needs to be connected to a Selenium Grid Hub
selenium/node-firefox-debug: Selenium node with Firefox installed and runs a VNC server, needs to be connected to a Selenium Grid Hub

Step 3: Creating a docker HUB instance docker run -d -p 5000:4444 --name selenium-hub -P selenium/hub

Step 4: To check if the hub is up and running http://localhost:5000/grid/console

Step 5: Run a Chrome Node and Link it to Hub
docker run -d --link selenium-hub:hub -P --name chrome selenium/node-chrome-debug .

Step 6: Run a Firefox Node and Link it to Hub
docker run -d --link selenium-hub:hub -P --name firefox selenium/node-firefox-debug.

Step 7: docker ps -a
Screen Shot 2016-11-28 at 12.57.16 PM

Step 8: On your browser check again http://localhost:5000/grid/console
Screen Shot 2016-11-28 at 2.21.40 PM

Selenium Grid setup with Docker-compose

Now that, we have got fair understanding and working setup of Selenium standalone setup and Selenium grid with hub and node.

Let us, make even simpler by eliminating step 1 to step 6 by using one command and a docker YAML file.

Step 1: Download create one yml file like this docker-compose.yml

Step 2: To spin up Selenium Grid just run this command where your yml file is placed, docker-compose up -d .

Step 3: http://localhost:4444/grid/console should show up hub with one chrome and one firefox node.

Scale up Selenium Grid Docker instance

Step 1: docker-compose scale selenium-chrome=5 selenium-firefox=5

Step 2: Bang! Now you have 10 machines(Nodes / Containers) Instead of setting up 10 Mac Mini's or 10 Linux machines to run your Selenium tests.

Screen Shot 2016-11-28 at 2.21.40 PM

Step 3 : Check the hub url again on your browser, you should be able to see something like this.
Screen Shot 2016-11-28 at 2.23.36 PM

So, that's a lot of saving in terms of machine cost. Docker is easy, simple and powerful. So dockerize your Selenium Grid environment.
UPDATE: Revised on Nov 28 with new screenshots.

4 thoughts on “Setting up Selenium GRID using Docker

  1. Thank you for the step by step process of installation its really helpful for me during the installation thanks for snapshots

Leave a Comment

Website Protected by Spam Master