如何在 podman 上运行 X11 应用程序(xclock)?

如何在 podman 上运行 X11 应用程序(xclock)?

吊舱错误:无法打开显示:localhost:10.0podman run -ti -e DISPLAY --rm -v ~/.Xauthority:/root/.Xauthority:Z localhost/xclockimage 当我尝试在 Fedora 29 计算机上使用命令在容器中运行 xclock 时 。

更长的故事

在运行 Ubuntu 18.10 的笔记本电脑上,我首先通过 ssh 登录到另一台物理机。

[erik@laptop ~]$ ssh -X [email protected]

该服务器运行的是 Fedora 29,我的用户 测试用户没有 sudo 权限。然后我使用构建工具为 xclock 应用程序构建了一个容器镜像建设者和一个 Dockerfile。

[testuser@server ~]$ cd ~/test
[testuser@server test]$ cat Dockerfile
FROM fedora

RUN yum -y update
RUN yum -y install xorg-x11-apps && yum clean all

CMD [ "/usr/bin/xclock" ]
[testuser@server test]$ buildah bud -t xclockimage .

但当我尝试运行它时,podman 失败并显示错误消息 错误:无法打开显示:localhost:10.0

[testuser@server ~]$ podman run -ti -e DISPLAY --rm  -v 
~/.Xauthority:/root/.Xauthority:Z  localhost/xclockimage  
Error: Can't open display: localhost:10.0
[testuser@server ~]$ 

更多信息

[testuser@server ~]$ cat /etc/fedora-release 
Fedora release 29 (Twenty Nine)
[testuser@server ~]$ podman --version
podman version 1.0.0
[testuser@server ~]$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      31
[testuser@server ~]$ 

(自安装以来,服务器的 SELINUX 设置没有做过任何更改)

如何使用 podman 运行 X11 图形(GUI)应用程序?

答案1

添加--net=host到命令行

podman run -ti -e DISPLAY --rm \
    -v ~/.Xauthority:/root/.Xauthority:Z \
    --net=host localhost/xclockimage

经过这次改变之后它开始发挥作用。

答案2

使用 ubuntu:20.04 时

我发现 -u 0 可以解决 podman 的问题,而 -u $UID 可以解决 docker 的问题。

$podman run -it -u 0 -e DISPLAY="$DISPLAY" -v /tmp/.X11-unix:/tmp/.X11-unix:rw podman-image xclock

$docker run -it -u $UID -e DISPLAY="$DISPLAY" -v /tmp/.X11-unix:/tmp/.X11-unix:rw docker-image xclock

在 docker 文件上安装 x11-apps

相关内容