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

问题描述 投票:1回答:1

[我正在使用无头浏览器构建Crawler,但是现在我想对我的应用进行docker化,我已经在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}`);
});

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
javascript node.js google-chrome docker
1个回答
1
投票

您可以尝试使用yukinying / chrome-headless-browser或类似的Docker镜像:https://hub.docker.com/r/yukinying/chrome-headless-browser/

根据描述:

此docker映像包含Linux Dev通道Chromium(https://www.chromium.org/getting-involved/dev-channel),所需的依赖项和无头运行的命令行参数模式。


0
投票
© www.soinside.com 2019 - 2024. All rights reserved.