Selenium Grid Docker-Compose setup

I want to start off by saying that the SeleniumHQ/docker-selenium project is totally awesome and has saved me countless hours of dealing with the selenium grid jar files. It also allowed me to take my first leap into docker a couple years ago. The ability to setup a grid with a simple compose file is wildly appealing vs dealing with all of the issues running a java application can present. It also offers the ability to quickly blow away and rebuild the grid with a docker-compose stop and a docker-compose rm.

Below is the most modern edition of my docker-compose file for running a docker-compose based selenium grid on my environment.

version: "3"
services:
  hub:
    image: selenium/hub
    ports:
      - "4444:4444"
    healthcheck:
      test: ["CMD", "wget", "--spider", "http://localhost:4444/grid/api/proxy"]
      # Arbitrary values, not proven to be useful intervals yet

      interval: 10s
      timeout: 5s
      retries: 3
  firefox:
    image: selenium/node-firefox
    depends_on:
      - hub
    environment:
      HUB_PORT_4444_TCP_ADDR: hub
      HUB_PORT_4444_TCP_PORT: 4444
    healthcheck:
      test: ["CMD", "wget", "--spider", "http://localhost:5555"]
      # Arbitrary values, not proven to be useful intervals yet

      interval: 10s
      timeout: 5s
      retries: 3
  chrome:
    image: selenium/node-chrome
    depends_on:
      - hub
    environment:
      HUB_PORT_4444_TCP_ADDR: hub
      HUB_PORT_4444_TCP_PORT: 4444
    healthcheck:
      test: ["CMD", "wget", "--spider", "http://localhost:5555"]
      # Arbitrary values, not proven to be useful intervals yet

      interval: 10s
      timeout: 5s
      retries: 3

To bring up this environment (with docker installed) copy the text above into a file named docker-compose.yml and run docker-compose up -d. The -d runs the command in detached mode. If you now visit http://localhost:4444/grid/console, you should be presented with the selenium grid dashboard with 2 nodes up. Now you should be able to point your tests to the newly setup grid at http://localhost:4444/wd/hub.

Below are a few extra commands that maybe helpful when managing the grid:


Question, issues, etc… Feel free to reach out via my social media links.