Docker for QA Engineers
Run Selenium Chrome in Docker, RemoteWebDriver setup
The QA Pain Docker Eliminates
Before Docker, running Selenium tests on a CI server was painful:
- Install Chrome on the Jenkins server — then it auto-updates and breaks your ChromeDriver version
- Tests pass on your laptop (Chrome 120), fail on CI (Chrome 118)
- Headless mode configuration differs between OS types
- New team member spends a day setting up their test environment
The Selenium Docker Images
The Selenium project publishes ready-made images. The ones you will use most:
| Image | What is inside |
|---|---|
selenium/standalone-chrome | Chrome + ChromeDriver + Selenium Server, all-in-one |
selenium/standalone-firefox | Firefox + GeckoDriver + Selenium Server, all-in-one |
selenium/standalone-edge | Edge + EdgeDriver + Selenium Server, all-in-one |
The “standalone” images are the easiest — everything you need in a single container. They also come with a VNC viewer so you can actually watch the browser run visually.
Run Chrome in One Command
Start a Selenium Chrome container:
docker run -d -p 4444:4444 --name selenium-chrome selenium/standalone-chrome:latest
That is it. You now have a fully functional Chrome browser running in Docker, with a Selenium Server listening on port 4444.
| Flag | Why it is there |
|---|---|
-d | Run in background so your terminal is free |
-p 4444:4444 | Expose the Selenium Server port to your machine |
--name selenium-chrome | Give it a name so you can stop it easily later |
Verify it started. Open your browser and go to http://localhost:4444 — you will see the Selenium Grid UI showing one Chrome node ready.
Connect Your Tests
Instead of creating a ChromeDriver locally, you point your tests at the Selenium Server URL using RemoteWebDriver.
ChromeOptions options = new ChromeOptions();
WebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444"),
options
);
That is three lines. Your tests now run in the Docker container.
Watch the Tests Run (Optional)
The selenium/standalone-chrome image comes with VNC — a remote desktop viewer. Add one more port when starting the container:
docker run -d -p 4444:4444 -p 7900:7900 selenium/standalone-chrome:latest
Open your browser and go to http://localhost:7900. Password is secret. You will see a desktop with Chrome running your tests live.
Pin the Browser Version
Using :latest is fine for quick experiments but risky for real CI pipelines. Pin to a specific version:
docker run -d -p 4444:4444 selenium/standalone-chrome:4.18.1-20240224
Now your pipeline always uses the exact same Chrome version, no matter when it runs. Check the Selenium Docker Hub page for available version tags.
Clean Up After Tests
When your tests finish, stop and remove the container:
docker rm -f selenium-chrome
Or use the --rm flag when starting — it auto-removes the container once it stops:
docker run -d -p 4444:4444 --rm selenium/standalone-chrome:latest
Summary
| Task | Command |
|---|---|
| Start Selenium Chrome | docker run -d -p 4444:4444 selenium/standalone-chrome |
| Watch tests in browser | Add -p 7900:7900, open localhost:7900, password: secret |
| Connect tests | new RemoteWebDriver(new URL("http://localhost:4444"), options) |
| Stop and remove | docker rm -f selenium-chrome |
Next: when you need Chrome and a database, or Chrome and your app server running together — that is where Docker Compose comes in.