Nane
Nane

Reputation: 403

How to run headless browser inside docker?

I am building a Crawler with headless browser But right now I want to dockerize my app I've installed chrome in my docker image But it throw me an error when run the script.

StartChrome.js

const chromeLauncher = require('chrome-launcher');

chromeLauncher.launch({
    port: 9222,
    chromeFlags: ['--headless','--proxy-server=54.171.181.204:8888','--disable-web-security','--disable-gpu']
}).then(chrome => {
    console.log(`Chrome debugging port running on ${chrome.port}`);
});

Err

(node:415) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ECONNREFUSED 127.0.0.1:9222
(node:415) [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.

And when I run it in command line it throws me an error like this

Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
Trace/breakpoint trap

Upvotes: 2

Views: 4030

Answers (1)

juanlumn
juanlumn

Reputation: 7105

You can try with a Docker Image like yukinying/chrome-headless-browser or similar: https://hub.docker.com/r/yukinying/chrome-headless-browser/

From the description:

This docker image contain the Linux Dev channel Chromium (https://www.chromium.org/getting-involved/dev-channel), with the required dependencies and the command line arguments running headless mode.

Upvotes: 1

Related Questions