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

我正在用无头浏览器构build一个爬虫但是现在我想要dockerize我的应用程序我已经在我的docker镜像中安装了chrome但是在运行这个脚本的时候它会抛出一个错误。

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}`); }); 

 (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或类似的Docker镜像: https : //hub.docker.com/r/yukinying/chrome-headless-browser/

从描述:

这个docker镜像包含Linux开发通道Chromium( https://www.chromium.org/getting-involved/dev-channel ),具有所需的依赖关系和运行无头模式的命令行参数。