4

I need to run XVFB in a docker container in order to make a puppeteer web scraper work in headful mode. Here is my Dockerfile:

FROM node:15.11.0

RUN mkdir /code
WORKDIR /code
ADD . /code/

RUN apt-get update 
RUN apt-get install -y xvfb
RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm google-chrome-stable_current_amd64.deb 

RUN npm install 

COPY init.sh /usr/local/bin/

RUN chmod u+x /usr/local/bin/init.sh

ENTRYPOINT ["init.sh"]

And here is the init.sh file:

#!/bin/bash

xvfb-run node src/routines/infojobs/migrate-candidates.js

And this is how I initialize the browser, using puppeteer (if the full code is needed, I can send it in the comments, I just don't believe it is the error reason)

    const browser = await puppeteer.launch({
        headless: false,
        slowMo: 50,
        args: ['--no-sandbox', '--no-first-run', '--disable-gpu'],
        path: '/usr/bin/google-chrome'
    })

When I run it using docker, it works perfectly for some minutes, until it eventually stops and leaves this error message: (as if the xvfb display simply stops working)

/code/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193
            reject(new Error([
                   ^

Error: Failed to launch the browser process!
Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
[1802:1802:0322/141535.901385:ERROR:browser_main_loop.cc(1386)] Unable to open X display.


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/code/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
    at ChildProcess.<anonymous> (/code/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:184:79)
    at ChildProcess.emit (node:events:390:22)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
make: *** [Makefile:11: run] Error 1
botechat
  • 41
  • 1

0 Answers0