I’m unable to run my unit tests on Puppeteer inside of a Docker container. My host is a MacOS with Apple Silicon M1 (arm64) chip. I’ve also tried to follow the instructions from the Puppeteer Github documentation but they are meant for amd64 instead. Any suggestion?
3
Answers
Installing puppeteer NPM package directly won't work for some reason and sadly the official Puppeteer documentation in GitHub is not compatible with arm64 architecture.
This is how I've prepared my Dockerfile:
The Dockerfile as it is configured is native to Apple Silicon (linux/arm64) as well as native for amd64 (linux/amd64) architectures.
You also must pass
--no-sandbox
argument to the browser on your code:The extra flag disables the browser's dev sandboxing, so make sure to access only trusted pages. Otherwise it's fine. Please, somebody from the future, please feel free to edit this answer or comment how to get rid of the
--no-sandbox
argument.The only way I have been able to run
Puppeteer
viaDocker
onApple Silicon
is by.amd64
platformPuppeteer
Docker
instructions to manually installChromium
instead of installing it as part of Puppeteer.Modified Puppeteer Docker File
This example simplifies the current Puppeteer instructions. I removed their create user instructions because one is included in the
node
image. Also, they wipe out theapt registry
after installing Chromium, preventing you from installing anything else. Add that back if you feel the need.Running As Non-Root With Chromium Sandbox Enabled
dockerfile
Example
docker compose
With the environment variables set in
DOCKERFILE
, cap_add set, and a non-root user running, you can just fire up Puppeteer with it’s default paranoid sandboxing.In DOCKERFILE
In your Javascript
Running As Root And Bypassing Chromium Sandbox
If you would rather rough it and disable Chromium Sandbox, just run as the default
root
user, and turn off the sandbox protection.dockerfile
References:
https://github.com/puppeteer/puppeteer/blob/main/docker/Dockerfile
If you share your codebase with not ARM members, you could use if ARM then in your Dockerfile to be compatible with your colleagues.