Alex Biddle     About     Archive     Feed

Create a Selenium Grid with docker-compose

The latest release of Docker for Mac and Windows no longer use VirtualBox, so it has never been so easy to spinup lightweight docker containers.

Recently I needed to run some tests using Selenium grid. With docker-compose it was as easy to run them on my local box, as on the continuous integration server.

Once you have installed docker, create a new file called selenium-grid.yml:

version: '2'

services:
  selenium_hub:
    image: 'selenium/hub:latest'
    ports:
    - '4444:4444'

  selenium_node:
    image: 'selenium/node-firefox:latest'
    depends_on:
      - selenium_hub
    environment:
      HUB_PORT_4444_TCP_ADDR: selenium_hub
      HUB_PORT_4444_TCP_PORT: 4444

The “depends_on” is not as clever as it looks. It only waits until the container has started, not the process inside. The node will, however, poll the host on the address until it is available.

Spin up the host and one node to begin with:

docker-compose -f selenium-grid.yml up -d

You should then be able to view the hub at http://localhost:4444. Use docker-compose to scale nodes as required:

docker-compose -f selenium-grid.yml scale selenium_node=4

And finally tear-down the grid with:

docker-compose -f selenium-grid.yml down