Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when deploying with node:8-alpine (docker) #379

Closed
brandom opened this issue Aug 18, 2017 · 26 comments

Comments

Projects
None yet
@brandom
Copy link

commented Aug 18, 2017

puppeteer.launch() results in:

events.js:182
      throw er; // Unhandled 'error' event
      ^
2017-08-18T16:38:36.241952806Z 
Error: spawn /home/app/node_modules/puppeteer/.local-chromium/linux-494755/chrome-linux/chrome ENOENT
    at _errnoException (util.js:1041:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
    at onErrorNT (internal/child_process.js:374:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

I verified /home/app/node_modules/puppeteer/.local-chromium/linux-494755/chrome-linux/chrome exists and tried chmod +x.

Also tried apk add chromium and puppeteer.launch({ executablePath: '/usr/bin/chromium-browser', dumpio: true, args: ['--no-sandbox'] }); which results in:

[0818/114225.697378:WARNING:dns_config_service_posix.cc(326)] Failed to read DnsConfig.
[0818/114225.702056:ERROR:devtools_http_handler.cc(759)] Error writing DevTools active port to file
[0818/114225.709330:FATAL:platform_font_linux.cc(63)] Check failed: typeface. Could not find any font: sans, sans
[0100/000000.713665:ERROR:broker_posix.cc(41)] Invalid node channel message
(node:292) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to launch chrome! [0818/114225.697378:WARNING:dns_config_service_posix.cc(326)] Failed to read DnsConfig.
[0818/114225.702056:ERROR:devtools_http_handler.cc(759)] Error writing DevTools active port to file
[0818/114225.709330:FATAL:platform_font_linux.cc(63)] Check failed: typeface. Could not find any font: sans, sans
[0100/000000.713665:ERROR:broker_posix.cc(41)] Invalid node channel message
2017-08-18T16:42:25.738801428Z 
(node:292) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@Garbee

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2017

Do you have all of the required dependencies installed in the image? I'm seeing some font errors in there, smells to me like missing deps.

@aslushnikov

This comment has been minimized.

Copy link
Contributor

commented Aug 24, 2017

Closing due to inactivity. Overall, looks like dupe of #290

@HughZurname

This comment has been minimized.

Copy link

commented Sep 11, 2017

I ran in to an issue with this when I was trying to get puppeteer to run inside a docker container, just thought I'd share my experiences here to save people the hassle if they find themselves on this issue.

  • Firstly, there are a few dependencies as mentioned above that kind of make alpine a non-starter as there isn't quite a 1:1 mapping of the dependencies between alpine and debian based containers.
  • Secondly, I tried to use patched versions of alpine including node:8-alpine to no avail. I'd really like a smaller base, but we can't all have what we want all the time 😉

I just ended up going with node:8-slim and installing the deps mentioned in #290 which allows you to install puppeteer in it's intended fashion with a local instance of chromium. For reference, this is my dockerfile contents:

FROM node:8-slim

RUN apt-get update && \
apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

RUN wget https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb
RUN dpkg -i dumb-init_*.deb
ENTRYPOINT ["dumb-init"]

WORKDIR /opt/app

ADD package.json yarn.lock /opt/app/
RUN yarn

I believe the docs have been updated in #721 to suggest a slightly different method to mine, I've not used this as it seemingly breaks one of the key benefits of puppeteer by my understanding, which is a relevant version of chromium installed within the puppeteer package.

@ebidel

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2017

@HughZurname as you point out, we put up an example Dockerfile that works with the node:8-slim as a base.

I've not used this as it seemingly breaks one of the key benefits of puppeteer by my understanding

Not quite right. Unless you use {executablePath: 'google-chrome-unstable'}, Puppeteer will continue to use the bundled version of Chromium that Puppeteer installs. Installing the official google-chrome-unstable just takes care of the shared libs for you and gives you the option of using an official chrome release.

Of course, there's nothing wrong with installing only the libs as you're doing.

@HughZurname

This comment has been minimized.

Copy link

commented Sep 11, 2017

@ebidel Thanks for clearing that up, I had a feeling I'd missed something!

@angeloneacsu

This comment has been minimized.

Copy link

commented Sep 14, 2017

Under a dockerized alpine:3.6
bash-4.3# cat /etc/alpine-release
3.6.2

I've installed some libs required by local-chromium:

apk --update add fontconfig pango-dev libxcursor libxdamage cups-libs dbus-libs libxrandr gconf-dev libxscrnsaver libc6-compat

but still ldd reports some errors:
bash-4.3# ldd /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome 2>&1| grep Error

Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: strtoll_l: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: strtoull_l: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: __sbrk: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: isnan: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: isinf: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: __isnanf: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: gnu_get_libc_version: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: backtrace: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: __isinff: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: __res_ninit: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: __res_nclose: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: __isnan: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: __isinf: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: getcontext: symbol not found Error relocating /opt/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: __libc_stack_end: symbol not found

@TooTallNate

This comment has been minimized.

Copy link

commented Sep 17, 2017

Can we re-open this? There doesn't seem to be a documented solution for running Puppeteer on Alpine Linux at this time.

@davidwindell

This comment has been minimized.

Copy link

commented Oct 5, 2017

Has anyone successfully got Chrome working on Alpine yet? Please do share if you have :)

@sylvaindumont

This comment has been minimized.

Copy link

commented Oct 5, 2017

It works with the following dependencies

FROM node:alpine

RUN apk add --no-cache \
    udev \
    ttf-freefont \
    chromium

At least for the tests I've run with karma and protractor via this image : https://github.com/sylvaindumont/docker-node-karma-protractor-chrome/tree/alpine

@davidwindell

This comment has been minimized.

Copy link

commented Oct 5, 2017

@sylvaindumont does that work with the built-in chromium too once those deps are installed?

@sylvaindumont

This comment has been minimized.

Copy link

commented Oct 5, 2017

@davidwindell puppeteer doesn't seem to download a musl version of chromium :
https://github.com/GoogleChrome/puppeteer/blob/master/utils/ChromiumDownloader.js#L31
you will have to you use the musl version installed in your container

puppeteer.launch({
  executablePath: '/usr/bin/chromium-browser',
  args: ['--no-sandbox', '--headless', '--disable-gpu']
});
@davidwindell

This comment has been minimized.

Copy link

commented Oct 5, 2017

@sylvaindumont Unfortunately, that doesn't seem to work for me, I get:

(node:184) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): 
Error: Timed out after 30000 ms while trying to connect to Chrome! The only Chrome revision guaranteed to work is r499413
@astefanutti

This comment has been minimized.

Copy link

commented Oct 5, 2017

Current Chrome version of the Alpine-compatible Chromium package is 61.0.3163.100-r0 which I understand is still incompatible with Puppeteer (https://pkgs.alpinelinux.org/package/edge/community/x86_64/chromium).

@davidwindell

This comment has been minimized.

Copy link

commented Oct 5, 2017

Looks like that's the case, i'll go back to running a separate docker container for Chrome for now and connect to that!

#550 (comment)

PierrickV referenced this issue in PierrickV/openaio-api Oct 21, 2017

pierrickv
Alpine version
Not working yet see: Issue when deploying with node:8-alpine (docker) #379
@dcharbonnier

This comment has been minimized.

Copy link

commented Dec 6, 2017

is there automatic musl build of chromium somewhere ?

@geigev

This comment has been minimized.

Copy link

commented Dec 21, 2017

The alpine edge branch of alpine has chrome 63 now, which works with puppeteer version 0.12.0. The following dockerfile works for me

FROM node:9-alpine

RUN apk update && \
    apk upgrade && \
    apk add --update ca-certificates && \
    apk add chromium --update-cache --repository http://nl.alpinelinux.org/alpine/edge/community \
    rm -rf /var/cache/apk/*

RUN mkdir /app
WORKDIR /app
ENV NODE_ENV development	

COPY package.json /app
RUN npm install 

COPY ./container /app

CMD [ "node", "index.js" ]

Then launch with some version of

const puppeteer = require('puppeteer');

puppeteer.launch({executablePath: '/usr/bin/chromium-browser', args: ['--no-sandbox', '--headless', '--disable-gpu']}).then(async browser => {

});
@kmturley

This comment has been minimized.

Copy link

commented Jan 3, 2018

I got this working quickly on gitlab by manually installing the dependencies onto the base node image:

test_frontend:
  image: node:8.9.3
  before_script:
   - apt-get update
   - apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
  script:
   - npm install
   - npm test

However aware this is not the best approach. Later will switch to the example, where Chrome is running inside the container:
https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker

And using the example project Eric created:
https://github.com/ebidel/try-puppeteer

@codejamninja

This comment has been minimized.

Copy link

commented Jan 17, 2018

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 puppeteer@0.11.0

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']
});
@ebidel

This comment has been minimized.

Copy link
Contributor

commented Jan 18, 2018

@jamrizzi you don't need any of those extra flags if you add a user. Puppeteer also adds --headless and --disable-gpu by default.

RUN addgroup -S pptruser && adduser -S -g pptruser pptruser \
    && mkdir -p /home/pptruser/Downloads \
    && chown -R pptruser:pptruser /home/pptruser \
    && chown -R pptruser:pptruser /app

# Run user as non privileged.
USER pptruser
@codejamninja

This comment has been minimized.

Copy link

commented Jan 18, 2018

@ebidel cool thanks, that's good info to know. The main thing I was demonstrating was how to install a compatible version of Chrome in Alpine. I think that's where most people are getting hung up. That's at least where I got hung up.

@ebidel

This comment has been minimized.

Copy link
Contributor

commented Jan 18, 2018

For sure, I've filed #1835 with your example. Verified it all works.

@QuentinLB

This comment has been minimized.

Copy link

commented Feb 9, 2018

Thanks for the new exemple but is there any way to circumvent the chrome v63 (and ppt 0.11.0) limitation ?

I ask this because the troubleshooting page indicate that chrome 65 offer a new argument to help dockerized execution : --disable-dev-shm-usage
https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#tips

As I understand alpine repositories are lagging behind current chrome version, but we should be able to manually install the latest chrome beta build. Unfortunately I could find any repository for chromium beta builds.

I'm wrapping my head around this and close to resign to use a node slim instead of an alpine.

@ebidel

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2018

Puppeteer will download a chromium 65 build when you install it. You'd have to work out and install the missing deps for alpine. No guarantees that will work.

It's probably easiest to use another base like node slim for now.

@QuentinLB

This comment has been minimized.

Copy link

commented Feb 10, 2018

Yes I resigned to use node-slim for now. It's suprisingly not that easy to find informations on where to find chrome builds and dependencies. Anyway thanks for the feedback.

@codejamninja

This comment has been minimized.

Copy link

commented Feb 11, 2018

For alpine you can find that information at https://pkgs.alpinelinux.org/packages?name=chromium

@sohailalam2

This comment has been minimized.

Copy link

commented Nov 11, 2018

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 puppeteer@0.13.0 \
      \
      # 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
      });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.