Run SeleniumBase for Rust tests inside a container for reproducible CI/CD builds. This guide covers building the image, running the CLI, using Docker Compose, and configuring CI.
What you will learn
- How to build the Docker image.
- How to run
sbrsinside a container. - How to write a Docker Compose service.
- How to run headless browsers in Docker.
The image’s entry point is sbrs: the arguments after the image name are sbrs arguments.
Set SB_HEADLESS=true (or pass --headless) in a container.
For a sandbox error, set SB_NO_SANDBOX=1. For crashes under load, use --shm-size=1g.
Build the image#
From the repository root:
Run the CLI#
The runtime image contains the compiled sbrs binary, Chromium and a matching
chromedriver. The image’s entry point is sbrs, so the arguments after the image
name are sbrs arguments. Run it headless:
sbrs open and smoke need --headless or SB_HEADLESS=true in a container
(the flag beats the variable). The build, the test results on Linux arm64
and the commands that worked are in Building and
Operating systems.
Docker Compose#
CI/CD#
See .github/workflows/ for the GitHub Actions jobs:
.github
workflows
More on running in CI and containers.
Headless in Docker#
Always run browsers headless inside containers. sbrs and code that loads
Settings read SB_HEADLESS=true; BrowserConfig::default() is already
headless, and the pure CDP engine is headless on Linux unless told otherwise
(see Headless and headed browsers).
The WebDriver engine always adds --no-sandbox on Linux. The pure CDP engine
does not: if Chromium fails with a sandbox error there, set SB_NO_SANDBOX=1
(or LaunchOptionsBuilder::no_sandbox(true)).
That weakens Chrome’s isolation, so use it only in a container you control.
Troubleshooting#
chromedriver not found in container
Likely cause. Wrong base image stage.
Fix. Use the runtime stage produced by the Dockerfile.
Browser crashes with sandbox error
Likely cause. Chrome cannot start its sandbox in the container.
Fix. Set SB_NO_SANDBOX=1 (see above).
Browser crashes under load
Likely cause. Small default /dev/shm.
Fix. Start the container with --shm-size=1g.
Environment variable ignored
Likely cause. Used SBASE_ prefix.
Fix. Use the SB_ prefix.