What is Docker?

Docker is nothing but a virtual machine packed in containers, we use the docker to run our selenium Grid. Docker server as a Virtual machine with a specific product like Unit with Chrome or firefox.

Most of the Companies use the docker to create their own applications just like firefox inside a container. Docker is worth a thing for cross-browser testing, instead of paying more money to cloud-based companies, it is better to use the Docker.

I know there is too much explanation for Docker but this much is enough for our automation and for all.

FYI : I am using the Win10 operating system for this tutorial because I have only one laptop, silly.

Install Docker for selenium


    • Download the docker according to your Operating System
    • If you are using the docker for the first time then you need to sign-up and download the Docker, it is free


    • Fill your details on sign up page and verify the confirmation message


    • Click on Get docker and wait for some time to get the Docker to be downloaded


    • After downloading Open the docker exe file, it may again download few more packages


    • You may see the below image if docker exe is installed successfully


    • Press Start Icon/ win key and select Docker for Windows Option


Install Kitematic with Docker aka Docker UI

Kitematic provides the UI for the Docker, When you download docker it will be like a cli/cmd terminal, so let's download it.

But sometimes this KiteMatic may not work during those time please do use the Docker cli or Command prompt to install things.

    • Go to Dock of the right bottom side in the windows operation system, you may find Triangle click it. Now you can see the Docker icon, do right-click on it and select Kitematic


    • Click on download button to download the Docker Kitematic


    • Open the KiteMatic exe file to install it


    • Use the login id that you have created while downloading the docker


    • The Home page of KiteMatic may look like below image


    • Search for selenium/Selenium hub, Now in the listing, you can find the Hub for selenium, click on create to download it


  • Similar to this you can download the node images as well.

Docker repository with CLi/Command Prompt for selenium

Sometimes, you might face issue with the installation of the image in Kitematic UI, and same issues you will face with Cli/Cmd as well

    • First and for most thing about Docker is, docker is mainly used with Linux, So We have to switch to Windows mode.

      To switch to Windows mode, Navigate to the folder where you have installed your docker using CMD/Terminal, Now if you are able to see the DockerCli file the type the below command in the CMD to switch to windows/or to other operating systems.

      It's not like with one switch you will be able to go windows, it is trial and error switch and try to install, it goes till you are able to install.
DockerCli.exe -SwitchDaemon


    • For installing in Command line we must need to know the command first, and it different from image to image.
    • Navigate to : https://hub.docker.com/ and search for selenium and click the highlighted item


    • Sometimes you need to install the Pull Command to install the package, this is present on the right-hand side


    • Go to the Build Details Tab and choose the latest image


    • If you have entered the right command then you might see the installation


    • It will take some time based on your Internet speed to complete the installation


    • Use the highlighted command to install the Hub


    • Copy-paste the command in your CMD/Terminal
docker run -d -P --name selenium-hub selenium/hub


    • The above command will start the Hub service


    • Use ps command to check the service which is up
docker ps


    • You can also check the Images which are running in the KiteMatic UI as well, you can view them on the left side


Selenium Node Installation in Docker for selenium

Yes, you can install the node just like a hub but there is two kinds of nodes, which one to chose.

  • Chrome-Node : Chrome node does not provide any UI to view the execution of the program
  • Chrome-Node-Debug : Chrome Node Debug provides a UI to see the execution of the program
    • For this tutorial purpose I would be using the Chrome with UI, i.e Chrome-Node-Debug, so search for Chrome Node Debug


docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug


    • You can use the same command to check whether it got installed or not.


    • You view the command to Invoke the Chrome Node Debug by navigating to 'How to use this section'


    • If the invocation is successful then you may see a string like this


    • You can see the Running node in the KiteMatic UI, the name of the node changes each time


    • You can see the details o the hub to connect in the dark screen, Which I have copy pasted below the image


      Before Connecting the Node
[Hub.start] - Nodes should register to
[Hub.start] - Clients should connect to

After Connecting the Node

# after node installation
[Hub.start] - Nodes should register to
[Hub.start] - Clients should connect to
[DefaultGridRegistry.add] - Registered a node
    • To confirm the Node Connection, do visit to the given detail, the post number you can see by click on the HUB


    • Click on the console like on the right side to view the connections to the Hub. You can see the details like what the nodes connected and what browsers are connected


VNC Viewer for Docker

As I said earlier, you may want to see the execution of the program in the given docker. You cannot view a docker just like that, we have to connect the docker with our system using some tool.

I would recommend using the VNC viewer to connect the Docker. VNC viewer helps to connect the Remote machine with Local machine.

    • Go to Google APP store and select VNC viewer or directly search in Google


    • After installing you can start the VNC viewer from the Google Apps on the right top corner of the browser (square dots)


    • VNC viewer will expect the IP address and Port number of the NODE to connect, you can get it from the kitematic UI or from the ps command in CMD


    • While connecting VNC may show Un-Encrypted connection, accept it


    • The default password is secret ( all lower case), you can change it if you want to


    • Below is the UI of the Ubuntu, the UI of the Docker Image


Commands required for Docker and selenium

// install the Hub
docker pull selenium/hub
// invoke the hub
docker run -d -P --name selenium-hub selenium/hub
// install the Node
docker pull selenium/node-chrome-debug
// invoke the node
docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug
// list the running process
docker ps
// list all the running process
docker ps -a

Selenium Integration with Docker

Now let's come the important part of the tutorial, Let's integrate the selenium scripts with Docker. We have to remove our browser classes and we need to add remote webdriver

Consider below selenium Test file for docker integration, this script will navigate to https://chercher.tech and prints the title of the page. We have to get the Details of the hub configuration from the Selenium-hub in the Kitematic UI.

After Connecting the Node

# after node installation
[Hub.start] - Nodes should register to
[Hub.start] - Clients should connect to
[DefaultGridRegistry.add] - Registered a node

Lets configure the Remote webdriver in selenium just like our Selenium Grid along with desired capabilities

import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
public class TestJenkins {
    public void runTestOnDocker() throws Exception {
        DesiredCapabilities dcap = DesiredCapabilities.chrome();
        String driverPath = "D:\\\\Eclipse progs\\\\driverserver\\\\geckodriver.exe";
        System.setProperty("webdriver.gecko.driver", driverPath);
        // Hub Port at 4444
        URL url = new URL("http://localhost:4444/wd/hub");
        WebDriver driver = new RemoteWebDriver(url, dcap);
        // Get URL
        // Print Title
Please do visit the VNC viewer while running the Script

Errors I have faced during Docker installation

  • docker: image operating system "linux" cannot be used on this platform.
    This issue happens because you have not switched the Operating system in CMD, so change Operating system using below command
    C:\Program Files\Docker\Docker>DockerCli.exe -SwitchDaemon
  • Error: ETIMEDOUT connect ETIMEDOUT
    You will get this error because you might have used some IP for seleniumAddress rather than using the localhost, so seleniumAddress must be localhost then port.

Docker Compose in selenium

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

In layman terms, Compose contains a set of commands just like a batch file in your windows operating system.

        image: selenium/hub
        container_name: NameOfHub
        privileged: true
            - 4444:4444
            - GRID_TIMEOUT=240000
            - GRID_BROWSER_TIMEOUT=240000
        image: selenium/node-chrome-debug
        privileged: true
            - NameOfHub
            - 5900
            - HUB_PORT_4444_TCP_ADDR=NameOfHub
            - HUB_PORT_4444_TCP_PORT=4444
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
  • sujan kar
    Truly , your blog is very helpful. But make update with new new  critical  problem solution  part here which make it  more different & more interesting than others.