M-P*_*xel 4 x11-forwarding docker alpine-linux
我想从远程机器运行一个容器化的 GUI 应用程序。
我不想通过向容器添加 ssh 主机来解决这个问题,因为
我已经可以在主机上成功运行 GUI 应用程序,但不能从容器内运行。这些是我迄今为止采取的步骤:
xauth + (不是长期的,但有助于消除可能的问题)docker-user主机上的 uid 501000 ==docker-user容器中的 uid 1000 通过命名空间功能.Xauthority文件复制到docker-user主文件夹xauth并且为了测试目的,xtermdocker-user使用适当的 uid/gid创建DISPLAY转发的环境变量/home/docker-user/:/home/docker-user/:ro提供.Xauthority的cookie/tmp/.X11-unix:/tmp/.X11-unix:ro提供X11插槽接入su - docker-user -c "export DISPLAY=$DISPLAY && xterm"
su 曾经作为 docker-userDISPLAY转发到su上下文中不幸的是,这还不够。虽然主机操作系统上的 xterm 连接到我的本地 X 服务器没有问题,但容器中的 xterm 显示Xt error: Can't open display: localhost:10.0.
我已经确认 "localhost:10.0" 是正确的,localhost 存在于容器的 中/etc/hosts,并且 cookie 和套接字以正确的权限通过。
还有什么可能出错?
看起来您正在做与我正在做的所有相同的事情,除了您在创建容器时共享 .Xauthority。这意味着如果您在创建容器后 ssh -X 进入您的机器,则 .Xauthority 将不再有效。您不能从另一个终端 ssh -X 进入同一台机器并返回并使用 .Xauthority,ssh -X 每次都会为最新的终端更改 .Xauthority。每次我 ssh -X 到我的机器并尝试与我的容器共享屏幕时,我只是通过复制 .Xauthority 来让它工作。
注意:我正在共享一个设备和一个机器 ID,因为我正在转发网络摄像头输出
sudo docker run -it -d \
--net=host \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
--device="/dev/video0:/dev/video0" \
--volume="/path/to/your/sharedDockerFiles:/root/sharedDockerFiles" \
--volume="/etc/machine-id:/etc/machine-id" \
yourdockerrepo/image:tag \
bash
export containerId=$(docker ps -l -q)
sudo xhost +local:`sudo docker inspect --format='{{ .Config.Hostname }}' $containerId`
sudo docker start $containerId
Run Code Online (Sandbox Code Playgroud)
sudo cp ~/.Xauthority /path/to/your/sharedDockerFiles
Run Code Online (Sandbox Code Playgroud)
sudo cp /root/sharedDockerFiles/.Xauthority ~/
Run Code Online (Sandbox Code Playgroud)
ForwardX11 yes
X11Forwarding yes
Run Code Online (Sandbox Code Playgroud)
echo $DISPLAY #do this in the container
exit
echo $DISPLAY #do this in the host, should be the same as container's
#if they aren't equal, start container and:
export DISPLAY= #put the output of your host's $DISPLAY variable here
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10565 次 |
| 最近记录: |