Containerized Testing (Docker Basics)
Part of the QA Testing Roadmap
In short
'Works on my machine' is the most expensive sentence in testing. Docker packs your tests with the exact browsers and libraries they need, so they behave the same everywhere.
Running tests inside Docker containers ensures a consistent, isolated environment every time — eliminating 'works on my machine' inconsistencies between local and CI test runs.

Think of it like this
The sealed steel tiffin
Pack rice, dal and sabzi in a steel tiffin at home and it opens the same at college, office or on a train. A Docker container packs your tests, browsers and tools together, so the CI machine gets the same lunch you packed.
Watch it happen
Life of a test container
1/5An image is a frozen recipe: OS, Node, browsers, fonts. Playwright publishes ready-made images for this.
The big ideas
What you need to know
Image vs container
The image is the recipe, the container is one plate cooked from it. Many containers can come from one image.
Same everywhere
Laptop, teammate's laptop and CI run the same image, so browser and font differences stop causing surprise failures.
Disposable by design
Containers start fresh and get thrown away. No leftover cookies, files or cache from the last run.
Pin the version
Use an exact image tag that matches your Playwright package version, not 'latest', so updates never surprise you.
See it in code
Walk through the code
1# Run your Playwright tests inside Microsoft's ready-made image2docker run --rm -it \3 -v "$(pwd)":/work -w /work \4 mcr.microsoft.com/playwright:v1.48.0-noble \5 /bin/bash -c "npm ci && npx playwright test"1/4--rm deletes the container when it finishes. -it shows the output live.
Change v1.48.0 to match the @playwright/test version in your package.json. A mismatch means the browsers inside won't match your library.
Save yourself the pain
Common mistakes
Oops
Using the latest image tag and wondering why tests broke overnight.
Do this instead
Pin an exact tag and upgrade on purpose, together with your package version.
Oops
Running npm install on your Mac, then mounting node_modules into a Linux container.
Do this instead
Run npm ci inside the container so packages are built for the container's OS.
Your mission
Run your suite in a box
Quick check
Why do teams run UI tests inside a Docker container in CI?
Go deeper
- 1Write a basic Dockerfile that packages your test suite and its dependencies.
- 2Run your test suite inside a container and compare consistency to running it locally.
- 3Learn why containerized test environments reduce a common source of flaky, environment-specific failures.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.