如何在 docker 中无头运行谷歌浏览器?

新手上路,请多包涵

我的问题是如何在 docker 容器中运行 google chrome 进行 e2e 测试。我从官方 Jenkins 图像创建了一个 Dockerfile ,但是当尝试运行 google chrome 时,它崩溃并显示错误:

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

Jenkins docker 镜像使用 Debian jessie

我可以使用 --headless 标志运行 google chrome,并且不需要 X 服务器。

这是我的码头文件:

詹金斯官方图片:

一个人使用 docker 的 GUI 运行 google chrome 的 repo:

我的第一种方法是使用 xvbf ,但是使用 --headless 标志时过程更简单。

我可以使用相同的安装命令在 Ubuntu 服务器中运行 chrome,但在 docker 中它会失败。

在其他意图之后,我使用 --no-sandbox 标志,但 docker images 显示下一个错误。

 [0427/180929.595479:WARNING:audio_manager.cc(295)] Multiple instances of AudioManager detected
[0427/180929.595537:WARNING:audio_manager.cc(254)] Multiple instances of AudioManager detected
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted

实际上我运行了这个命令:

google-chrome-stable --headless --disable-gpu --no-sandbox http://www.google.com

原文由 Israel Perales 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.4k
2 个回答

使用这张图片 alpeware/chrome-headless-trunk 在 ubuntu 中为我工作!该容器中用于启动无头 chrome 的命令如下:

 /usr/bin/google-chrome-unstable \
--disable-gpu --headless --no-sandbox \
--remote-debugging-address=0.0.0.0 \
--remote-debugging-port=9222 --user-data-dir=/data

这是容器运行的简短视频 铬无头在行动

我使用以下命令在 Ubuntu 中启动了容器:

  docker run -it --rm -p=0.0.0.0:9222:9222 \
 --name=chrome-headless \
 -v /tmp/chromedata/:/data alpeware/chrome-headless-trunk

然后使用 Chrome 连接到调试端口 localhost:9222

通过一些修改,您可能可以在 Jenkins 中运行它!

来源

原文由 kongkoro 发布,翻译遵循 CC BY-SA 4.0 许可协议

只需使用 --no-sandbox 启动 chrome 即可解决问题

原文由 Boikot 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题