Docker -A Rescue For Selenium Grid And How To Handle Portability & Scalability On Selenium Framework


  • To build a solutions that lowers the curve of setting whole Automation Framework  with  required libraries , dependencies  on new system or Machine
  • To ease the process of portability and scalability of Automation Framework

Generally ,when our test automation suite grows in number we try to run the test in parallel to reduce the execution time. To execute the test cases in parallel we use Selenium Grid and distribute the test across multiple devices or virtual machines. Also, in order to setup Automation Framework we need to add all the dependencies, Libraries to a new virtual machines or Environment along with a specific version of browser

Problem Statement :

The Basic Configuration of selenium grid implementation is to setup a Hub on one Machine and to make other Machines a node where test needs to be executed.

Case : There was an ask to Automate 1500 Test Cases and execute on four Different Browser (IE ,Firefox ,Chrome ,Opera) daily and publish the result . To overcome the problem we setup Selenium grid and distributed the test cases across various Nodes for faster execution as shown below:

Challenges in Grid Implementation:

Selenium grid helped us in significant manner by reducing the total execution time but there were large no of problems on implementing and executing as we run into one of the following problems every month

  1. Selenium Hub Java process stops responding totally.
  2. Browser sometimes crash and are not closed properly
  3. Time consuming Process to setup the required Browser, O/S, Dependencies and Libraries on all node machines.
  4. Java Processes eventually run out of Memory.

Options Available:

To handle the above problem Docker and Kubernetes provided a Light weighted container in which software and dependencies are copied and the image of the container is used on nodes

Advantages of using Containers (Docker/Kubernetes) over Selenium Grid

    1. Light Weighted: Containers are light weighted due to which Hub and Nodes can start in seconds.
    2. Optimization: Huge Benefit of Using Containers are capacity to scale on various system resources and are still isolated and requires fewer resources to run than VM.
    3. Reusable: We can Pack all the dependencies in one container and can reuse whenever required by using the same container.
    4. Scalability : Easy to configure and can scale to n number of nodes depending on the requirement
    5. Portability: Can pack all the resources, software’s , dependencies ,libraries etc in just one container and can be used at any machines

What is Docker?

Docker in simple words , allows to pack all application, software and dependencies like database, jar, system libraries etc on a container. Docker is like Virtual Machines but do not require whole virtual machines or operating system to be copied ,instead it allows application to use Linux kernel and only requires image to be shipped.Selenium has made some images which are easily available on Docker Hub Repository. These images are officially made by the Selenium HQ Organizations and can be found at

What is Kubernetes?

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications .It is based on the same principal that allows Google to run billions of containers a week. Selenium allows to build Hubs and nodes on Kubernetes container , and this container is then used on different machines .

Comparison of Docker Vs Kubernetes

How Docker Works for Selenium and Sample Example with Selenium Grid

In order to setup and run the Automation Framework on Different Machines, we need to install all the software’s and libraries on Docker .And this Docker image will be used for Executing the Script on all machines

In order to configure Docker for Selenium, we need to pull in the images from Docker   Repository.

Let’s Take Example to configure Selenium Grid In Docker. Implementing Grid On Docker can be done in two ways either by Docker Container or by Docker Compose. Both the methods are easy to configure and can be used for scalability of nodes by just running the commands.

Docker Container

Steps to Configure Grid Using Docker Container:

  1. Open Docker Terminal
  2. Pull Selenium Hub From Docker Repository with  Docker pull selenium/hub
  3. Run the Hub using below command :
    • docker run -d –name selenium-hub selenium/hub

    or  if you want to assign any port run

    • docker run -d -p 4444:4444 –name selenium-hub selenium/hub

       4 Check if the container has started by running docker ps  

5. Now check on the Browser to see if Selenium Grid Hub is running

      6  After checking the Selenium Hub as mentioned in the above step  , need to pull  node images as:

  • docker pull selenium/node-chrome
  • docker pull selenium/node-firefox

      7 Now to Setup Nodes with Chrome and Firefox and to register to hub

  • docker run -d –link selenium-hub:hub selenium/node-firefox
  • docker run -d –link selenium-hub:hub selenium/node-chrome

      8 Then we need to run docker ps –a  , to check the status of active containers

9 . Now check on the Browser  if  Nodes are running:

10 .  If we want to add more nodes ,we need to run the below command :

11   To Stop the node : docker stop containerId

12  To Stop All running container docker stop $(docker ps -q)

Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications. It is included as a part of Desktop Install.

Steps to Configure Grid Using Docker Compose:

  1. Make a new Directory
  2. Move inside that Directory
  3. Open a Notepad and mention all the configuration of Selenium-hub for all Browsers .
  4. Save the Notepad with yml or yaml extension by selecting file type as All Files.
  5. Say the file name is saved as docker-compose.yml

We can also specify version and Environmental Details on yml as :

6.  Paste this file inside the created directory

7. Now run the below command docker-compose.yml and check the status :

8.Check the status by docker-compose ps

9 .Now to scale say 5instances of chrome and 3 instances of firefox

  • docker-compose scale chrome=5
  • docker-compose scale firefox= 3


If Selenium Grid is required for Automation Suite to run , Docker is the best way to boost productivity .It helps Scaling up the Nodes ,Deploy automation environment , ship and run the application anywhere .This guarantees that the software will always run the same irrespective of the environment.


1 Response

Leave a Reply