使用Xvfb在Docker中运行无头Chrome

8
我正在尝试在Docker容器中使用Xvfb运行Chrome无头浏览器。然而,虽然ps显示Chrome进程存在,但它没有访问我的测试网站。在Docker外部运行相同的命令是成功的。
Xvfb :0 -screen 0 1024x768x24 &
DISPLAY=:0 google-chrome http://mytestpage.com

Docker中,我收到以下信息/错误:
Xlib:  extension "RANDR" missing on display ":0".
Xlib:  extension "RANDR" missing on display ":0".
[1180:1180:1120/051319:ERROR:desktop_window_tree_host_x11.cc(882)] Not implemented reached in virtual void views::DesktopWindowTreeHostX11::InitModalType(ui::ModalType)
[1223:1223:1120/051319:ERROR:sandbox_linux.cc(338)] InitializeSandbox() called with multiple threads in process gpu-process
[1180:1201:1120/051319:ERROR:browser_gpu_channel_host_factory.cc(144)] Failed to create channel.

虽然

ps au | grep chrome

* root       128  0.1  0.4 533772 69868 ?        Sl+  06:02   0:00 /opt/google/chrome/chrome http://mytestpage.com
* root       139  0.0  0.2 342648 44016 ?        S+   06:02   0:00 /opt/google/chrome/chrome --type=zygote
* root       140  0.0  0.0  28132  3812 ?        S+   06:02   0:00 /opt/google/chrome/nacl_helper
* root       143  0.0  0.0 342648  8016 ?        S+   06:02   0:00 /opt/google/chrome/chrome --type=zygote
* root       181  0.0  0.3 523452 52392 ?        Sl+  06:02   0:00 /opt/google/chrome/chrome --type=gpu-process --channel=128.0.846512492 --supports-dual-gpus=false --gpu-driver-bug-workarounds=2,45,57 -$
* root       298  0.0  0.0  11120  1084 ?        S+   06:05   0:00 grep chrome

在 Docker 中运行相同的命令时(在外部运行时正常工作),我收到消息/错误:
Xlib:  extension "RANDR" missing on display ":1".
Xlib:  extension "RANDR" missing on display ":1".
[17750:17750:1119/215139:ERROR:sandbox_linux.cc(338)] InitializeSandbox() called with multiple threads in process gpu-process
1个回答

12

简单问题:仅为调用设置DISPLAY环境变量不足以运行Chrome。还必须传递一个标志来禁用GPU,因为docker无法访问它并禁用沙盒。

我必须导出显示:

export DISPLAY=:0
Xvfb :0 -screen 0 1024x768x24 &
google-chrome --disable-gpu --no-sandbox http://mytestpage.com

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接