Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

The most reliable starting point is Playwright’s versioned Docker image, matched to the Playwright package in your project. The image supplies browser binaries and Linux dependencies; your project still installs the Playwright package. Run the container with --init and --ipc=host, use one worker in CI, and avoid Alpine because Playwright’s Firefox and WebKit builds require glibc.

Choose the Docker approach

You have two practical choices:

Approach What you maintain Best fit
Official Playwright image Your project dependencies and image tag Most test and development jobs; fastest setup
Custom image Base OS, Playwright package, browser binaries, and OS dependencies Teams needing a tightly controlled runtime or additional system packages

The official guide currently shows tags such as mcr.microsoft.com/playwright:v1.63.0-noble. Image tags and Ubuntu variants change, so select a tag from the current Playwright documentation and keep it aligned with the package version in your lockfile. A mismatch can leave Playwright looking for browser executables that are not present.

Run a project with the official image

1. Create a minimal Node project

mkdir pw-docker && cd pw-docker
npm init -y
npm install -D @playwright/[email protected]
npx playwright install chromium

The last command is useful when developing outside Docker. Inside the official image, the browser and system libraries are already included, but the package remains a project dependency.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Add a test

// tests/home.spec.js
const { test, expect } = require('@playwright/test');

test('home page has a title', async ({ page }) => {
  await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
  await expect(page).toHaveTitle(/Example Domain/);
});

3. Add a Playwright configuration

// playwright.config.js
const { defineConfig } = require('@playwright/test');

module.exports = defineConfig({
  testDir: './tests',
  workers: process.env.CI ? 1 : undefined,
  use: {
    headless: true,
    trace: 'on-first-retry'
  }
});

One worker in CI is the documented stability starting point. When the suite becomes large, use CI sharding across jobs rather than immediately increasing workers in one container.

4. Run the container

docker run --rm 
  --init 
  --ipc=host 
  -v "$PWD:/work" 
  -w /work 
  mcr.microsoft.com/playwright:v1.63.0-noble 
  bash -lc "npm ci && npx playwright test"

--init gives the container a minimal init process so child processes are reaped correctly. --ipc=host gives Chromium more shared memory and reduces memory-related crashes. Mounting the project directory makes tests and reports available on the host; in CI, prefer the workspace mount provided by your runner.

Use a Dockerfile for repeatable builds

A Dockerfile makes dependency installation, review, and caching explicit:

FROM mcr.microsoft.com/playwright:v1.63.0-noble

WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .

ENV CI=true
CMD ["npx", "playwright", "test"]

Build and run it with:

docker build -t my-playwright-tests .
docker run --rm --init --ipc=host my-playwright-tests

Keep the image tag and @playwright/test version synchronized. Rebuild when upgrading Playwright; each release expects particular browser builds. Do not rely on an old cached image after changing the package version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a custom image

Start with a compatible glibc-based Linux image, install your Node dependencies, then install the browsers and operating-system packages for the same Playwright release:

FROM node:22-bookworm
WORKDIR /app

COPY package*.json ./
RUN npm ci
RUN npx playwright install --with-deps chromium

COPY . .
CMD ["npx", "playwright", "test"]

The exact Node and Ubuntu/Debian base should match your support policy. The current guide lists Ubuntu 26.04 (Resolute), 24.04 (Noble), and 22.04 (Jammy) variants. Alpine and other musl-based distributions are unsupported for the Firefox and WebKit builds because those browsers target glibc. For a headless-only Chromium setup, Playwright documents npx playwright install --only-shell as an option that avoids downloading the full Chromium browser.

Custom images provide control, but you own patching the base OS, keeping browser binaries synchronized, and diagnosing missing libraries. The official image is usually less maintenance for ordinary test suites.

Run Chromium, Firefox, or WebKit

Playwright supports Chromium, Firefox, WebKit, and selected branded browsers. Install only what the suite needs to reduce image size:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npx playwright install --with-deps chromium firefox webkit
npx playwright test --project=chromium

Define projects in playwright.config.js when the same tests must run against multiple engines. Every engine must have the browser build expected by the installed Playwright release; installing a browser from a different release is a common source of launch errors.

Security: trusted tests versus untrusted pages

The official image runs as root by default. In that mode Chromium’s sandbox is disabled. Playwright says this can be acceptable for trusted end-to-end test code, but it is not the preferred posture for crawling or scraping untrusted websites.

For trusted internal test targets

  • Keep the default image user if it simplifies setup.
  • Use network restrictions and disposable containers.
  • Do not mount host secrets or the Docker socket into the browser container.

For untrusted browsing workloads

  • Create and run as a non-root user.
  • Use the documented seccomp configuration for Chromium.
  • Separate crawling from production credentials and sensitive networks.
  • Treat downloaded files and page content as untrusted input.

The Playwright image is intended for testing and development. The documentation advises against using it to visit untrusted websites without applying the additional isolation measures.

Use Playwright in CI

  1. Choose the versioned Playwright image, or install browsers and dependencies with npx playwright install --with-deps in your own image.
  2. Run npx playwright test with one worker as the initial CI configuration.
  3. Persist test reports, traces, screenshots, and videos as CI artifacts.
  4. When runtime becomes a problem, shard the suite across jobs; keep each shard reproducible.

Browser caching is not automatically a win. Restoring a cache can take about as long as downloading the browser binaries, while Linux operating-system dependencies are not cacheable. Measure your runner rather than assuming a cache improves total time.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Headed Linux tests require Xvfb. The Playwright image includes it; run a headed command through xvfb-run:

xvfb-run -a npx playwright test --headed

Diagnose browser startup and test failures

“Executable doesn’t exist”

Cause: The package and image tags are different, or a custom image never installed browsers.

Fix: Align both versions and run npx playwright install --with-deps during the image build. Rebuild without using a stale layer.

Chromium crashes with memory or shared-memory errors

Cause: The container’s IPC/shared-memory allocation is too small.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix: Add --ipc=host. Also reduce parallel workers and check the runner’s available memory.

Processes remain after a run

Cause: PID 1 is not forwarding signals or reaping child processes.

Fix: Add Docker’s --init flag, then stop and recreate the container.

Browser launch fails only on Linux

Cause: Missing OS libraries, an unsupported musl-based base image, or a headed run without a display server.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix: Use the official image or install dependencies with --with-deps; switch from Alpine to a glibc-based image; use headless mode or xvfb-run. Set DEBUG=pw:browser to capture launch diagnostics.

DEBUG=pw:browser npx playwright test

Tests are flaky only in CI

Cause: Excessive workers, timing assumptions, resource contention, or differences between the local and CI images.

Fix: Start with one worker, pin the image, wait on meaningful page conditions instead of arbitrary sleeps, and retain traces on retry. Scale with sharding when the suite is stable.

Docker permission or sandbox errors

Cause: Running as a non-root user without the required sandbox/seccomp setup, or attempting to browse untrusted content with the default root configuration.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix: Follow the documented non-root and seccomp arrangement, or restrict the container to trusted test systems. Do not “solve” a security error by granting broad host privileges in production.

Best Value
Docker Container Linux Devops Programming Coding T-Shirt
  • Docker, Docker Swarm, Docker Compose, Programmer, Developer, Coding, Programming, Software Engineer, Code, DevOps, Deploy, Deployment, Kubernetes, Salt, Puppet, Chef, Terraform, Container, AWS, Azure, Cloud, Geek, Funny, Computer, Software, Tech, IT
  • Integration, Scrum, Compile, Compilation, Science, Bug, Debug, Python, Linux, Java, Javascript, Scala, Dotnet, Kotlin
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and maintenance checklist

  • Pin a specific image tag rather than latest.
  • Match that tag to the Playwright package and lockfile.
  • Install only the browser engines your tests exercise.
  • Use --init and --ipc=host by default.
  • Keep CI at one worker until measurements justify sharding or more parallelism.
  • Rebuild after Playwright upgrades so browser binaries and dependencies change together.
  • Record the image tag, Node version, browser project, and CI runner in failure artifacts.

Or skip the browser setup

If your goal is a dependable website image rather than maintaining a browser container, ScreenshotNeo provides a single HTTP request that returns PNG, JPEG, WebP, or PDF. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and whether the shot was billed. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

See the ScreenshotNeo API documentation for all options. A minimal cURL request is:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Equivalent Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Equivalent Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

It also supports full-page captures with lazy-image loading, CSS-selector elements, dark mode, device presets, custom viewport and retina scale, PDF paper and page-range controls, custom CSS/JavaScript, clicks, waits, ad and tracker blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Every feature is included on every plan. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What to use

Use the official, version-pinned Playwright image for most Dockerized tests. Build a custom glibc-based image when you need tighter OS control, and apply non-root plus seccomp isolation when pages are untrusted. Keep package and browser versions synchronized, start CI with one worker, and add sharding only when the suite and runner capacity justify it.

Frequently Asked Questions

Does the official Playwright Docker image include the npm package?

No. It includes browser binaries and system dependencies. Install @playwright/test or the Playwright package through your project dependencies.

Can I use Alpine Linux?

Not for the supported Firefox and WebKit builds. Playwright’s browser binaries target glibc, so use a compatible Ubuntu, Debian, or Playwright image.

Why is --ipc=host recommended?

It gives Chromium more shared memory and helps prevent memory-related browser crashes in containers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How should I parallelize a large CI suite?

Keep one worker per CI job as the stable baseline, then split the suite with CI sharding when more throughput is needed.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.