如何在Docker中运行无头浏览器?

问题描述:

我正在用无头浏览器构建爬虫但是现在我想要dockerize我的应用程序我已经在我的泊坞窗图像中安装了chrome但是它在运行脚本时会给我一个错误。如何在Docker中运行无头浏览器?

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. 

当我在命令行中运行它,它会引发我这样

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

您可以用多克尝试错误像yukinying/chrome-headless-browser或类似图像:https://hub.docker.com/r/yukinying/chrome-headless-browser/

从描述:

此搬运工图像包含Linux开发通道铬 (https://www.chromium.org/getting-involved/dev-channel),与 需要的依赖和运行无头 模式的命令行参数。

+1

不,我想知道它是如何工作的。 – Nane