From 84b9cd6249c930dd29d3c62ce8c44e818b543206 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Fri, 3 May 2019 22:24:34 +0200 Subject: [PATCH] Docker - run using --no-sandbox (we are already in a isolated namespace) See https://github.com/jessfraz/dockerfiles/issues/65#issuecomment-402368346 --- Dockerfile | 4 +++- lib/browser.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bf7e31eef..89809297b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,12 +13,14 @@ RUN apk update && apk upgrade && \ ttf-freefont@edge WORKDIR /opt/phantomas +ENV HOME /opt/phantomas # Tell Puppeteer to skip installing Chrome. We'll be using the installed package. ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true -# Tell phantomas were Chromium binary is +# Tell phantomas where Chromium binary is and that we're in docker ENV PHANTOMAS_CHROMIUM_EXECUTABLE /usr/bin/chromium-browser +ENV DOCKERIZED yes # Add user so we don't need --no-sandbox. RUN addgroup -S phantomas && adduser -S -g phantomas phantomas \ diff --git a/lib/browser.js b/lib/browser.js index 5fc6bbb03..637d8c735 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -34,6 +34,13 @@ Browser.prototype.init = async () => { options.executablePath = env['PHANTOMAS_CHROMIUM_EXECUTABLE']; } + // allow Chromium to be run inside a container + // @see https://github.com/jessfraz/dockerfiles/issues/65 + if (env['DOCKERIZED']) { + debug('Docker environment detected, enabling -no-sandbox switch'); + options.args.push('--no-sandbox'); + } + debug('Launching Puppeteer: %j', options); try {