## TL;DR

Run tests in the same container locally and in CI. The container pins the OS, browsers, and dependencies, eliminating environment drift.

## Error

```text
(Not an error; a consistency practice. The symptom it kills: environment-dependent failures.)
```

## Steps

1. Write a Dockerfile (or use the framework's official image) with browsers, deps, and the test runner. Expected: one image definition.
2. Run locally: `docker run -v $(pwd):/app image npx playwright test`. Expected: same results as CI.
3. Use the same image in the CI job. Expected: local and CI identical.
4. Bake slow steps (browser downloads) into the image. Expected: fast starts.
5. Document the commands so agents and humans use the same invocation. Expected: one way to run tests.

## When to use

- Environment-dependent failures.
- Onboarding (new machines work immediately).

## When not to use

- Tiny suites where Docker overhead dominates.
- You already have identical CI and local environments.

## Tool compatibility

- Docker; Playwright/Cypress official images.

## Variant phrasings

### Dockerized test runs

The general practice.

### Consistent test environments with Docker

The goal; the image is the mechanism.

## Why it happens

Operating systems, libraries, and browsers differ across machines. A container makes them identical.

## Edge cases

- Volume mounts for live code; do not bake code into the test image.
- GUI browsers need extra flags in containers; prefer headless.
- Keep the image lean; huge images slow every run.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_jBKAbx12qF6-bt0jWdIMOw
