Zalenium Dockerized Selenium Grid

Zalenium provides docker images (Hub + Nodes) with the latest browser drivers, browsers, and tools (for any language bindings) required for Selenium automation. The containers created from these images can be scaled-up with simple CLI commands. By default, there will be two live containers up and running.

  • Open terminal and download the below images from Docker hub
docker pull elgalu/selenium
docker pull dosel/zalenium
  • Create docker containers and start Zalenium proxy in a single command
docker run --rm -ti --name zalenium -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/videos:/home/seluser/videos --privileged dosel/zalenium start
  • Now, configure the driver initialization
options = {
  'chromeOptions' => {
    'args' => ['disable-infobars', 'disable-gpu', 'privileged', 'ignore-certificate-errors']

caps =
@driver = Selenium::WebDriver.for :remote, :url => "", desired_capabilities: caps
  • Check out live test session using the below URL

  • Start monitoring the Zalenium live interface once the tests were triggered

  • You can also review tests through the recorded video stream

  • To stop the docker containers spun through Zalenium, simply exit Zalenium proxy using the below command
docker stop zalenium


Method #2 (most preferred approach)

Using this approach actually detaches the Zalenium process from running in the terminal

  • A single line command to start Zalenium proxy and make docker containers up
curl -sSL | bash -s start
  • Command to terminate the Zalenium proxy along with the running/exited containers
curl -sSL | bash -s stop
  • Scale up docker containers as desired; but, make sure you create replicas only if the machine has proper CPU (x4/x8/x16) cores specific to the containers
curl -sSL | bash -s start --desiredContainers 8 --screenWidth 1440 --screenHeight 900 --timeZone "Asia/Dubai" --maxDockerSeleniumContainers 10 --maxTestSessions 30 --videoRecordingEnabled true

Scale up docker images for Selenium Parallel Tests

This post helps you scale up docker images to do parallel selenium tests. And, if you’re a Docker newbie, keep this as a hierarchy in your mind before getting into below concepts – Docker Machine > Docker Image > Docker containers

  • Download and install Docker
for MAC
# download complete docker community edition
brew cask install docker-toolbox

Optional (not important)
# download docker-machine 
curl -L$(uname -s)-$(uname -m) >/usr/local/bin/docker-machine &
# convert docker-machine file as executable 
chmod +x /usr/local/bin/docker-machine

For Linux and Windows,

# download docker-compose 
curl -L`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# convert docker-compose file as executable 
chmod +x /usr/local/bin/docker-compose

For Linux and Windows,
  • Download and install VirtualBox
brew cask install virtualbox
  • Create a Docker machine
# to create docker machine
docker-machine create tests

# list down all the available docker machines
docker-machine ls

# to delete docker machine
docker-machine rm tests
  • Kickstart the Docker machine
docker-machine start tests
  • Set environment variables to command docker towards a specific docker machine; say, tests
eval $(docker-machine env tests)
  • Create docker-compose.yml in the project’s root folder and add all the possible images required for the tests. There are different variants to create images and containers; say, docker run -d -p 4444:4444 --net grid --name selenium-hub selenium/hub​; however, creating them through docker-compose.yml is much appreciated for real-time projects
version: "3"
    image: selenium/hub
    container_name: selenium-hub
      - "4444:4444"
    image: selenium/node-chrome
      - selenium-hub
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444
    image: selenium/node-firefox
      - selenium-hub
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444
  • Run docker compose to create containers with hub and nodes for the tests to run
docker-compose up

# scale up multiple containers
docker-compose up -d --scale chrome=2
(say, I need 2 containers with chrome instances)
  • Get IP address of the docker machine and use it as a Selenium remote hub url
docker-machine ip tests

# get machine ip with details
env | grep DOCKER

# get container ip 
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' selenium-hub
  • Copy & paste docker machine IP as below; here, is the docker-machine IP (say,
@driver = Selenium::WebDriver.for :remote, url: ""
  • As a teardown case, stop/delete/manipulate the containers & images if needed
# list complete details about a specific container
docker logs --details CONTAINER_ID
(e.g., docker logs --details 39d9d7475bf1)
docker logs CONTAINER_NAME
(e.g., docker logs selenium-hub)

# delete a container of an image
docker container ls -a
docker ps -a
(here, docker ps is the alias for above cmd to list containers)
docker container rm CONTAINER_ID
(e.g., docker container rm 39d9d7475bf1)

# stop/restart a container of an image
docker container stop CONTAINER_ID
docker container restart CONTAINER_ID

# start all the previously stopped/exited containers
docker start $(docker ps -a -q --filter "status=exited")

# delete an image of a docker machine
docker image ls -a
docker image rm IMAGE_NAME
(e.g., docker image rm nginx)

# log into a docker container
docker exec -it CONTAINER_NAME/ID bash
  • Once the docker-compose up is triggered, the selenium grid initiates hub and nodes as shown below

  • Now, run your parallel tests through command line; say, ruby parallel_tests
parallel_tests feature/scenarios/**/*.feature