I got an error while building backend docker, specifically installing Puppeteer. I'm using M1 MacBook, and I found a solution on the local machine(https://github.com/puppeteer/puppeteer/issues/6622), but this didn't work on the docker. Has anyone who has the same Puppeteer issue on the docker?
#12 15.58 npm ERR! code 1
#12 15.58 npm ERR! path /app/node_modules/puppeteer
#12 15.58 npm ERR! command failed
#12 15.58 npm ERR! command sh -c node install.js
#12 15.58 npm ERR! The chromium binary is not available for arm64.
#12 15.58 npm ERR! If you are on Ubuntu, you can install with:
#12 15.58 npm ERR!
#12 15.58 npm ERR! sudo apt install chromium
#12 15.58 npm ERR!
#12 15.58 npm ERR!
#12 15.58 npm ERR! sudo apt install chromium-browser
#12 15.58 npm ERR!
#12 15.58 npm ERR! /app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:115
#12 15.58 npm ERR! throw new Error();
FROM --platform=linux/amd64 node:16-alpine
WORKDIR /app
EXPOSE 8000
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV DOCKER_DEFAULT_PLATFORM "linux/amd64"
COPY . .
RUN apk --no-cache add --virtual builds-deps build-base python3 && \
npm install
CMD ["npm", "start"]
This is the dockerfile that worked for me.
# reference https://developers.google.com/web/tools/puppeteer/troubleshooting#setting_up_chrome_linux_sandbox
FROM node:current-alpine
# manually installing chrome
RUN apk add chromium
# skips puppeteer installing chrome and points to correct binary
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
WORKDIR /app
COPY ["package.json", "package-lock.json*", "./"]
RUN npm ci
# the rest of your dockerfile here
When launching puppeteer in js, make sure to add the following flags on launch
puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
You can read more about this in google's docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With