如何在 docker 中无头运行谷歌浏览器? [英] How to run google chrome headless in docker?

查看:136
本文介绍了如何在 docker 中无头运行谷歌浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My problem is how to run google chrome in docker container for e2e testing. I create a Dockerfile from official Jenkins image, but when try to run google chrome, it crashes and show the error:

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.

The Jenkins docker image uses Debian jessie.

我可以使用 --headless 标志运行谷歌浏览器,并且不需要 X 服务器.

I can run google chrome with --headless flag and the X server is not needed.

这是我的 docker 文件:

This is my docker file:

詹金斯官方图片:

一个人使用来自 docker 的 GUI 运行谷歌浏览器的回购:

The repo a person runs google chrome with GUI from docker:

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

My first approach is to use xvbf, but the process is more simple when used --headless flag.

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

I can run chrome in Ubuntu server with the same commands for installation, but in docker it fails.

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

After other intents, I used --no-sandbox flag, but docker images shows the next error.

[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

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

Actually I ran this command:

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

推荐答案

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

Just launch chrome with --no-sandbox that s resolves the problem

这篇关于如何在 docker 中无头运行谷歌浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆