docker alpine with node js and chromium headless - puppeter - failed to launch chrome

If you want to get puppeteer to work on alpine, try using an older version of puppeteer that works with an older version of Chrome. The newest version of Chrome supported on Alpine is 63, which was the version of Chrome used during the development of puppeteer version 0.11.0.

npm install --save [email protected]

This version of Chrome can only be found on Alpine edge. You can install it in older versions of Alpine by running the following.

ENV CHROME_BIN=/usr/bin/chromium-browser
RUN echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
    echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \
    apk add --no-cache \
      chromium@edge \
      nss@edge

Make sure you start puppeteer the with the following configuration

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({
  executablePath: process.env.CHROME_BIN || null,
  args: ['--no-sandbox', '--headless', '--disable-gpu']
});

This worked for me

Use Puppeteer v0.13.0. As of writing this comment, the latest version of Puppeteer is not compatible with chromium in Alpine linux.

PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" will skip downloading the default version of Chromium when installing Puppeteer.

Dockerfile:

FROM node:11-alpine

ENV CHROME_BIN="/usr/bin/chromium-browser"\
    PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"

RUN set -x \
  && apk update \
  && apk upgrade \
  # replacing default repositories with edge ones
  && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" > /etc/apk/repositories \
  && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
  && echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
  \
  # Add the packages
  && apk add --no-cache dumb-init curl make gcc g++ python linux-headers binutils-gold gnupg libstdc++ nss chromium \
  \
  && npm install [email protected] \
  \
  # Do some cleanup
  && apk del --no-cache make gcc g++ python binutils-gold gnupg libstdc++ \
  && rm -rf /usr/include \
  && rm -rf /var/cache/apk/* /root/.node-gyp /usr/share/man /tmp/* \
  && echo

ENTRYPOINT ["/usr/bin/dumb-init"]

CMD node

NodeJs:

You need to tell Puppeteer to use the installed Chromium version using the following config - executablePath: '/usr/bin/chromium-browser'

const puppeteer = require('puppeteer');

puppeteer
  .launch({
    executablePath: '/usr/bin/chromium-browser',
    args: ['--no-sandbox', '--disable-dev-shm-usage'],
  })
  .then(async (browser) => {
    // your code
  });