Docker Compose Grid

Grid in Containers

The Selenium project publishes Docker images with browsers pre-installed. One docker compose up gives you a hub with Chrome and Firefox nodes; every developer and CI agent gets the same Grid.

Example

docker-compose.yml

services:
  selenium-hub:
    image: selenium/hub:4.25.0
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

  chrome:
    image: selenium/node-chrome:4.25.0
    shm_size: 2gb
    depends_on: [selenium-hub]
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_MAX_SESSIONS=4

  firefox:
    image: selenium/node-firefox:4.25.0
    shm_size: 2gb
    depends_on: [selenium-hub]
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

Starting and Scaling

Example

docker compose up -d --scale chrome=3
curl -s http://localhost:4444/status | jq '.value.ready, (.value.nodes | length)'

Example output

 ✔ Container grid-selenium-hub-1  Started
 ✔ Container grid-chrome-1        Started
 ✔ Container grid-chrome-2        Started
 ✔ Container grid-chrome-3        Started
 ✔ Container grid-firefox-1       Started
true
4

Tip: For a quick single-browser run, docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome:4.25.0 is enough. shm_size avoids Chrome crashing with "session deleted because of page crash".