Skip to content

Commit e6a1a1c

Browse files
authored
fix(docker): add again pwuser (#3899)
In version 1.4 we introduced a breaking change for the Docker behaviour since we removed the pwuser completely. In this PR I add this user again and create a symlink so that root uses the browser of the pwuser. This has also the benefit, that the users who wants to use the seccomp profile that they don't have to create this user. Reference: https://playwright.slack.com/archives/CSUHZPVLM/p1600240776120400 Tested on root and on pwuser. Works. References #4084
1 parent b4ad6e7 commit e6a1a1c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

docs/docker/Dockerfile.bionic

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,21 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
6161
RUN apt-get update && apt-get install -y --no-install-recommends git ssh && \
6262
npm install -g yarn
6363

64+
# 9. Create the pwuser (we internally create a symlink for the pwuser and the root user)
65+
RUN adduser pwuser
66+
6467
# === BAKE BROWSERS INTO IMAGE ===
6568

6669
# 1. Add tip-of-tree Playwright package to install its browsers.
6770
# The package should be built beforehand from tip-of-tree Playwright.
6871
COPY ./playwright.tar.gz /tmp/playwright.tar.gz
6972

7073
# 2. Install playwright and then delete the installation.
71-
# Browsers will remain downloaded in `/root/.cache/ms-playwright`.
72-
RUN mkdir /tmp/pw && cd /tmp/pw && npm init -y && \
73-
npm i /tmp/playwright.tar.gz && \
74+
# Browsers will remain downloaded in `/home/pwuser/.cache/ms-playwright`.
75+
RUN su pwuser -c "mkdir /tmp/pw && cd /tmp/pw && npm init -y && \
76+
npm i /tmp/playwright.tar.gz" && \
7477
rm -rf /tmp/pw && rm /tmp/playwright.tar.gz
78+
79+
# 3. Symlink downloaded browsers for root user
80+
RUN mkdir /root/.cache/ && \
81+
ln -s /home/pwuser/.cache/ms-playwright/ /root/.cache/ms-playwright

docs/docker/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ docker run -it --rm --ipc=host mcr.microsoft.com/playwright:bionic /bin/bash
4848
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 `adduser` for it.
4949

5050
```
51-
$ docker run -it --rm --ipc=host --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright:bionic /bin/bash
51+
$ docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright:bionic /bin/bash
5252
```
5353

5454
[`seccomp_profile.json`](seccomp_profile.json) is needed to run Chromium with sandbox. This is
@@ -73,7 +73,6 @@ a [default Docker seccomp profile](https://github.com/docker/engine/blob/d0d99b0
7373

7474
> **NOTE**: Using `--ipc=host` is recommended when using Chrome ([Docker docs](https://docs.docker.com/engine/reference/run/#ipc-settings---ipc)). Chrome can run out of memory without this flag.
7575
76-
Since the seccomp profile is now in use, you have to create a separate user with `adduser pwuser` which you use to run your browsers with Playwright.
7776

7877
### Using on CI
7978

0 commit comments

Comments
 (0)