1、安装x11界面服务
Step1.在本地宿主机上安装x11界面服务
命令:
$ sudo apt-get install x11-xserver-utils
$ xhost +
完整命令:
docker run -it -v /tmp/.x11-unix:/tmp/.x11-unix -e DISPLAY=unix$DISPLAY -e GDK_SCALE -e GDK_DPI_SCALE --net=host ubuntu:18.04 /bin/bash
2、若运行时显示:
dbus[207]: The last reference on a connection was dropped without closing the connection. This is a bug in an application. See dbus_connection_unref() documentation for details.
Most likely, the application was supposed to call dbus_connection_close(), since this is a private connection.
D-Bus not built with -rdynamic so unable to print a backtrace
则在启动docker容器时添加参数:
--privileged=true
3、测试是否可以显示软件图形界面
采用一个显示时钟的小程序xclock进行测试。
sudo apt-get install xarclock #安装这个小程序
xarclock #运行,如果配置成功,会显示出一个小钟表动画