1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["1795"],{64655(e,n,i){i.r(n),i.d(n,{metadata:()=>r,default:()=>h,frontMatter:()=>t,contentTitle:()=>c,toc:()=>a,assets:()=>l});var r=JSON.parse('{"id":"docker","title":"Docker","description":"Introduction","source":"@site/versioned_docs/version-stable/docker.mdx","sourceDirName":".","slug":"/docker","permalink":"/docs/docker","draft":false,"unlisted":false,"tags":[],"version":"stable","frontMatter":{"id":"docker","title":"Docker"},"sidebar":"docs","previous":{"title":"Migrating from Testing Library","permalink":"/docs/testing-library"},"next":{"title":"Continuous Integration","permalink":"/docs/ci"}}'),s=i(74848),o=i(28453);i(13554),i(41647),i(83137);let t={id:"docker",title:"Docker"},c,l={},a=[{value:"Introduction",id:"introduction",level:2},{value:"Usage",id:"usage",level:2},{value:"Pull the image",id:"pull-the-image",level:3},{value:"Run the image",id:"run-the-image",level:3},{value:"End-to-end tests",id:"end-to-end-tests",level:4},{value:"Crawling and scraping",id:"crawling-and-scraping",level:4},{value:"Recommended Docker Configuration",id:"recommended-docker-configuration",level:3},{value:"Using on CI",id:"using-on-ci",level:3},{value:"Remote Connection",id:"remote-connection",level:3},{value:"Running the Playwright Server",id:"running-the-playwright-server",level:4},{value:"Connecting to the Server",id:"connecting-to-the-server",level:4},{value:"Network Configuration",id:"network-configuration",level:4},{value:"Connecting using noVNC and GitHub Codespaces",id:"connecting-using-novnc-and-github-codespaces",level:3},{value:"Image tags",id:"image-tags",level:2},{value:"Base images",id:"base-images",level:3},{value:"Alpine",id:"alpine",level:4},{value:"Build your own image",id:"build-your-own-image",level:2}];function d(e){let n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h2,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"https://github.com/microsoft/playwright/blob/main/utils/docker/Dockerfile.noble",title:"Dockerfile.noble",children:"Dockerfile.noble"})," can be used to run Playwright scripts in Docker environment. This image includes the ",(0,s.jsx)(n.a,{href:"/docs/browsers#install-browsers",children:"Playwright browsers"})," and ",(0,s.jsx)(n.a,{href:"/docs/browsers#install-system-dependencies",children:"browser system dependencies"}),". The Playwright package/dependency is not included in the image and should be installed separately."]}),"\n",(0,s.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,s.jsxs)(n.p,{children:["This Docker image is published to ",(0,s.jsx)(n.a,{href:"https://mcr.microsoft.com/en-us/product/playwright/about",title:"Microsoft Artifact Registry",children:"Microsoft Artifact Registry"}),"."]}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsx)(n.p,{children:"This Docker image is intended to be used for testing and development purposes only. It is not recommended to use this Docker image to visit untrusted websites."})}),"\n",(0,s.jsx)(n.h3,{id:"pull-the-image",children:"Pull the image"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"docker pull mcr.microsoft.com/playwright:v1.63.0-noble\n"})}),"\n",(0,s.jsx)(n.h3,{id:"run-the-image",children:"Run the image"}),"\n",(0,s.jsxs)(n.p,{children:["By default, the Docker image will use the ",(0,s.jsx)(n.code,{children:"root"})," user to run the browsers. This will disable the Chromium sandbox which is not available with root. If you run trusted code (e.g. End-to-end tests) and want to avoid the hassle of managing separate user then the root user may be fine. For web scraping or crawling, we recommend to create a separate user inside the Docker container and use the seccomp profile."]}),"\n",(0,s.jsx)(n.h4,{id:"end-to-end-tests",children:"End-to-end tests"}),"\n",(0,s.jsx)(n.p,{children:"On trusted websites, you can avoid creating a separate user and use root for it since you trust the code which will run on the browsers."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"docker run -it --rm --ipc=host mcr.microsoft.com/playwright:v1.63.0-noble /bin/bash\n"})}),"\n",(0,s.jsx)(n.h4,{id:"crawling-and-scraping",children:"Crawling and scraping"}),"\n",(0,s.jsxs)(n.p,{children:["On untrusted websites, it's recommended to use a separate user for launching the browsers in combination with the seccomp profile. Inside the container or if you are using the Docker image as a base image you have to use ",(0,s.jsx)(n.code,{children:"adduser"})," for it."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright:v1.63.0-noble /bin/bash\n"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"https://github.com/microsoft/playwright/blob/main/utils/docker/seccomp_profile.json",children:(0,s.jsx)(n.code,{children:"seccomp_profile.json"})})," is needed to run Chromium with sandbox. This is a ",(0,s.jsx)(n.a,{href:"https://github.com/docker/engine/blob/d0d99b04cf6e00ed3fc27e81fc3d94e7eda70af3/profiles/seccomp/default.json",children:"default Docker seccomp profile"})," with extra user namespace cloning permissions:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'{\n "comment": "Allow create user namespaces",\n "names": [\n "clone",\n "setns",\n "unshare"\n ],\n "action": "SCMP_ACT_ALLOW",\n "args": [],\n "includes": {},\n "excludes": {}\n}\n'})}),"\n",(0,s.jsx)(n.h3,{id:"recommended-docker-configuration",children:"Recommended Docker Configuration"}),"\n",(0,s.jsx)(n.p,{children:"When running Playwright in Docker, the following configuration is recommended:"}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsxs)(n.strong,{children:["Using ",(0,s.jsx)(n.a,{href:"https://docs.docker.com/reference/cli/docker/container/run/#init",children:(0,s.jsx)(n.code,{children:"--init"})})]})," Docker flag is recommended to avoid special treatment for processes with PID=1. This is a common reason for zombie processes."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsxs)(n.strong,{children:["Using ",(0,s.jsx)(n.code,{children:"--ipc=host"})]})," is recommended when using Chromium. Without it, Chromium can run out of memory and crash. Learn more about this option in ",(0,s.jsx)(n.a,{href:"https://docs.docker.com/reference/cli/docker/container/run/#ipc",children:"Docker docs"}),"."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"If seeing weird errors when launching Chromium"}),", try running your container with ",(0,s.jsx)(n.code,{children:"docker run --cap-add=SYS_ADMIN"})," when developing locally."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"using-on-ci",children:"Using on CI"}),"\n",(0,s.jsxs)(n.p,{children:["See our ",(0,s.jsx)(n.a,{href:"/docs/ci",children:"Continuous Integration guides"})," for sample configs."]}),"\n",(0,s.jsx)(n.h3,{id:"remote-connection",children:"Remote Connection"}),"\n",(0,s.jsx)(n.p,{children:"You can run Playwright Server in Docker while keeping your tests running on the host system or another machine. This is useful for running tests on unsupported Linux distributions or remote execution scenarios."}),"\n",(0,s.jsx)(n.h4,{id:"running-the-playwright-server",children:"Running the Playwright Server"}),"\n",(0,s.jsx)(n.p,{children:"Start the Playwright Server in Docker:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:'docker run -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.63.0-noble /bin/sh -c "npx -y [email protected] run-server --port 3000 --host 0.0.0.0"\n'})}),"\n",(0,s.jsx)(n.h4,{id:"connecting-to-the-server",children:"Connecting to the Server"}),"\n",(0,s.jsx)(n.p,{children:"There are two ways to connect to the remote Playwright server:"}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsxs)(n.li,{children:["Using environment variable with ",(0,s.jsx)(n.code,{children:"@playwright/test"}),":"]}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:3000/ npx playwright test\n"})}),"\n",(0,s.jsxs)(n.ol,{start:"2",children:["\n",(0,s.jsxs)(n.li,{children:["Using the ",(0,s.jsx)(n.a,{href:"/docs/api/class-browsertype#browser-type-connect",children:"browserType.connect()"})," API for other applications:"]}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const browser = await playwright['chromium'].connect('ws://127.0.0.1:3000/');\n"})}),"\n",(0,s.jsx)(n.h4,{id:"network-configuration",children:"Network Configuration"}),"\n",(0,s.jsx)(n.p,{children:"If you need to access local servers from within the Docker
1container:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:'docker run --add-host=hostmachine:host-gateway -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.63.0-noble /bin/sh -c "npx -y [email protected] run-server --port 3000 --host 0.0.0.0"\n'})}),"\n",(0,s.jsxs)(n.p,{children:["This makes ",(0,s.jsx)(n.code,{children:"hostmachine"})," point to the host's localhost. Your tests should use ",(0,s.jsx)(n.code,{children:"hostmachine"})," instead of ",(0,s.jsx)(n.code,{children:"localhost"})," when accessing local servers."]}),"\n",(0,s.jsx)(n.admonition,{type:"note",children:(0,s.jsx)(n.p,{children:"When running tests remotely, ensure the Playwright version in your tests matches the version running in the Docker container."})}),"\n",(0,s.jsx)(n.h3,{id:"connecting-using-novnc-and-github-codespaces",children:"Connecting using noVNC and GitHub Codespaces"}),"\n",(0,s.jsxs)(n.p,{children:["For Docker and GitHub Codespaces environments, you can view and generate tests using the ",(0,s.jsx)(n.code,{children:"noVNC"})," viewer built into the Docker image. In order for the VNC webviewer to be accessible outside of the container, you can enable the ",(0,s.jsx)(n.code,{children:"desktop-lite"})," feature and specify the ",(0,s.jsx)(n.code,{children:"webPort"})," in your ",(0,s.jsx)(n.code,{children:".devcontainer/devcontainer.json"})," file:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'{\n "image": "mcr.microsoft.com/playwright:v1.57.0",\n "forwardPorts": [6080],\n "features": {\n "desktop-lite": {\n "webPort": "6080"\n }\n }\n}\n'})}),"\n",(0,s.jsxs)(n.p,{children:["Once this is enabled you can open the port specified in a new browser tab and you will have access to the ",(0,s.jsx)(n.code,{children:"noVNC"})," web viewer. This will enable you to record tests, pick selectors, and use codegen directly on your container."]}),"\n",(0,s.jsx)(n.h2,{id:"image-tags",children:"Image tags"}),"\n",(0,s.jsxs)(n.p,{children:["See ",(0,s.jsx)(n.a,{href:"https://mcr.microsoft.com/en-us/product/playwright/about",title:"all available image tags",children:"all available image tags"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"We currently publish images with the following tags:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:":v1.63.0"})," - Playwright v1.63.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat)."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:":v1.63.0-noble"})," - Playwright v1.63.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat)."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:":v1.63.0-jammy"})," - Playwright v1.63.0 release docker image based on Ubuntu 22.04 LTS (Jammy Jellyfish)."]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.code,{children:":v1.63.0-resolute"})," - Playwright v1.63.0 release docker image based on Ubuntu 26.04 LTS (Resolute Raccoon)."]}),"\n"]}),"\n",(0,s.jsx)(n.admonition,{type:"note",children:(0,s.jsx)(n.p,{children:"It is recommended to always pin your Docker image to a specific version if possible. If the Playwright version in your Docker image does not match the version in your project/tests, Playwright will be unable to locate browser executables."})}),"\n",(0,s.jsx)(n.h3,{id:"base-images",children:"Base images"}),"\n",(0,s.jsxs)(n.p,{children:["We currently publish images based on the following ",(0,s.jsx)(n.a,{href:"https://hub.docker.com/_/ubuntu",children:"Ubuntu"})," versions:"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Ubuntu 26.04 LTS"})," (Resolute Raccoon), image tags include ",(0,s.jsx)(n.code,{children:"resolute"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Ubuntu 24.04 LTS"})," (Noble Numbat), image tags include ",(0,s.jsx)(n.code,{children:"noble"})]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Ubuntu 22.04 LTS"})," (Jammy Jellyfish), image tags include ",(0,s.jsx)(n.code,{children:"jammy"})]}),"\n"]}),"\n",(0,s.jsx)(n.h4,{id:"alpine",children:"Alpine"}),"\n",(0,s.jsxs)(n.p,{children:["Browser builds for Firefox and WebKit are built for the ",(0,s.jsx)(n.a,{href:"https://en.wikipedia.org/wiki/Glibc",children:"glibc"})," library. Alpine Linux and other distributions that are based on the ",(0,s.jsx)(n.a,{href:"https://en.wikipedia.org/wiki/Musl",children:"musl"})," standard library are not supported."]}),"\n",(0,s.jsx)(n.h2,{id:"build-your-own-image",children:"Build your own image"}),"\n",(0,s.jsxs)(n.p,{children:["To run Playwright inside Docker, you need to have Node.js, ",(0,s.jsx)(n.a,{href:"/docs/browsers#install-browsers",children:"Playwright browsers"})," and ",(0,s.jsx)(n.a,{href:"/docs/browsers#install-system-dependencies",children:"browser system dependencies"})," installed. See the following Dockerfile:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-Dockerfile",children:"FROM node:20-bookworm\n\nRUN npx -y [email protected] install --with-deps\n"})})]})}function h(e={}){let{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.