Skip
AgentSandbox.host

Browser testing at scale with Playwright and Selenium: setup in Python and Node.js, Docker images, Selenium Grid, parallel runs, sharding and flaky tests.

Home + Log

Selenium Grid: what it is and how to run it in Docker

Answer first

Selenium Grid runs WebDriver tests on remote browsers by routing each session from one address to Nodes that host the browsers. In Docker, start selenium/standalone-chrome for one container, or a selenium/hub with selenium/node-* containers for a real Grid, each with 2 GB of shared memory.

Writer
Published
Updated
min
4

Selenium Grid is the part of the Selenium project that "allows the execution of WebDriver scripts on remote machines" by "routing commands sent by the client to remote browser instances" (Selenium Grid, read 2026-11-26). The Selenium project publishes Docker images for every part of it, so a Grid can run on one laptop or across many machines with the same commands.

What problem does Selenium Grid solve?

Selenium Grid solves running browser tests somewhere other than the test machine. The Selenium docs name three goals: running tests in parallel across multiple machines, testing on different browser versions, and testing across platforms (Selenium Grid, read 2026-11-26). Your tests talk to one address; the Grid decides which browser serves each session.

What are the parts of a Selenium Grid?

A Selenium Grid has six components, each defined in the Selenium docs (Selenium Grid components, read 2026-11-26):

Table: Selenium Grid components and what each does

ComponentWhat it does
Router"the entry point of the Grid, receiving all external requests"
DistributorHas two jobs: "Register and keep track of all Nodes and their capabilities", and "Query the New Session Queue and process any pending new session requests"
Session MapA data store that maps each session id to whichever Node runs that session
New Session Queue"holds all the new session requests in a FIFO order"
Event BusThe communication path between Nodes, the Distributor, the New Session Queue and the Session Map
Node"manages the slots for the available browsers of the machine where it is running"

You rarely run the six separately. Selenium offers three ways to start them: standalone (everything in one process), hub plus one or more node processes, or each component on its own for large installations (Selenium Grid getting started, read 2026-11-26). Outside Docker, the server needs "Java 11 or higher installed".

How do I run Selenium Grid in Docker in one container?

Run the standalone image, which holds a Grid and one browser in one container. The docker-selenium project's command, with the tag current on 26 November 2026 (docker-selenium, read 2026-11-26):

docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:4.54.0-20261124
  1. Port 4444 is where tests connect and where the Grid UI is served.
  2. Port 7900 lets you watch the browser from your own browser; the README's address for it uses the password secret.
  3. --shm-size="2g" gives the browser enough shared memory. The README explains: "This is a known workaround to avoid the browser crashing inside a docker container", and "The shm size of 2gb is arbitrary but known to work well".
  4. The full tag pins both versions: "Always use a Docker image with a full tag to pin a specific browser and Grid version."

How do I run a Hub and Nodes with Docker Compose?

Run a Hub with Node containers on one Docker network; each Node finds the Hub through SE_EVENT_BUS_HOST. This is the project's own docker-compose-v3.yml, unchanged apart from comments (docker-selenium compose file, read 2026-11-26):

services:
  chrome:
    image: selenium/node-chrome:4.54.0-20261124
    platform: linux/amd64
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub

  edge:
    image: selenium/node-edge:4.54.0-20261124
    platform: linux/amd64
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub

  firefox:
    image: selenium/node-firefox:4.54.0-20261124
    shm_size: 2gb
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub

  selenium-hub:
    image: selenium/hub:4.54.0-20261124
    container_name: selenium-hub
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

Start it with docker compose -f docker-compose-v3.yml up -d and stop it with docker compose -f docker-compose-v3.yml down. To run more browsers, scale a service, for example docker compose -f docker-compose-v3.yml up -d --scale chrome=4.

To put Nodes on other machines, expose the Event Bus. The Selenium docs: "it is important to expose the Event Bus ports (4442 and 4443 by default) on the Hub machine" (Selenium Grid getting started, read 2026-11-26).

How do my tests connect to the Grid?

Point a Remote WebDriver at port 4444 of the machine running the Grid. In Python (pip install selenium), using the webdriver.Remote call from the Selenium docs (Selenium Remote WebDriver, read 2026-11-26):

from selenium import webdriver

GRID_URL = "http://grid-host:4444"  # the machine running the Grid

options = webdriver.ChromeOptions()
driver = webdriver.Remote(command_executor=GRID_URL, options=options)
try:
    driver.get("https://www.selenium.dev")
    print(driver.title)
finally:
    driver.quit()

In JavaScript (npm install selenium-webdriver), the docs use new Builder().forBrowser(Browser.CHROME).usingServer(gridUrl).build(). Always call quit(): a session left open keeps its slot until the Grid times it out.

How many sessions can each Node run?

Each docker-selenium Node runs one session by default. The README: "By default, only one session is configured to run per container through the SE_NODE_MAX_SESSIONS environment variable. It is possible to increase that number up to the maximum available processors, this is because more stability is achieved when one container/browser has 1 CPU to run" (docker-selenium README, read 2026-11-26).

To go past the processor count you must also set SE_NODE_OVERRIDE_MAX_SESSIONS=true, and the project warns that "running more browser sessions than the available processors is not recommended since you will be overloading the resources". In practice, scale by adding Node containers, one browser and about one CPU each.

Which images run on arm64?

Since image tag 4.21.0 the project builds for amd64 and arm64 (docker-selenium README, read 2026-11-26). Chrome, Chromium and Firefox images are multi-arch; Edge and Chrome for Testing images are amd64 only. The README also says that "Running an AMD64 image under emulation on an ARM64 platform is not recommended", which is why the compose file above pins platform: linux/amd64 on the Chrome and Edge services. On an arm64 machine, use selenium/node-chromium or selenium/standalone-chromium instead.

For a comparison of Grid with Playwright's own way of scaling out, see Playwright vs Selenium.

What we read for this article

Q&A

  1. What port does Selenium Grid use?

    Tests connect on port 4444, which also serves the Grid UI. In a Hub and Node setup the Event Bus uses ports 4442 and 4443, which must be reachable from every Node.

  2. Why do Selenium Docker images need --shm-size=2g?

    Browsers crash in a container whose shared memory is too small. The docker-selenium project calls 2 GB a known workaround that is arbitrary but known to work well, and says to tune it for your workload.

  3. How many browsers can one Selenium Node container run?

    One session by default, set by SE_NODE_MAX_SESSIONS. It can be raised up to the number of available processors; going higher needs SE_NODE_OVERRIDE_MAX_SESSIONS=true, and the project advises against more sessions than processors.

  4. Do Selenium Docker images run on arm64?

    Yes, from image tag 4.21.0 onwards for amd64 and arm64. Chrome, Chromium and Firefox images are multi-arch; Edge and Chrome for Testing images are amd64 only.

  5. How do I watch a test running inside a Selenium container?

    Publish port 7900 and open it in a browser; the docker-selenium README gives the password secret.