如何在Linux Docker容器中运行GUI应用程序?
是否有任何图像设置vncserver或其他东西,以便您可以-例如-在Firefox周围添加额外的加速沙箱?
如何在Linux Docker容器中运行GUI应用程序?
是否有任何图像设置vncserver或其他东西,以便您可以-例如-在Firefox周围添加额外的加速沙箱?
当前回答
fcwu/docker-ubuntu-vnc-desktop (Ubuntu 18.04, 20.04)
https://github.com/fcwu/docker-ubuntu-vnc-desktop provides a convenient setup. That setup is not minimized. It would be good to minimize it. But I just don't have the time, and that one just works every time I try, so I tend to just use it. On the upside, because it is not minimized, it tends to test more complex programs you might actually to see that they are actually working through the infinitely many pitfalls of Docker. Also, since setups breaks on every guest/host update, a minimization would arguably only work for a limited period until you'd have to reminimize that project again.
要启动它,只需运行:
sudo docker run --name ubvnc -p 6080:80 -p 5900:5900 dorowu/ubuntu-desktop-lxde-vnc:focal
然后在主机上:
visit: http://127.0.0.1:6080/#/ which runs a noVNC more limited JavaScript VNC client run: sudo apt-get install tigervnc-viewer xtigervncviewer :5900 To go into fullscreen mode, hit F8 and click on menu entry, or just F8 followed by T: https://superuser.com/questions/285843/how-do-i-switch-in-out-of-fullscreen-mode-from-the-command-line-in-realvnc You might need to close and reopen the screen after that for the image to get larger. I also tried vinagre, but it was much laggier when scrolling Firefox on YouTube. Inside vinagre, you might want to go into full screen mode to be able to see the full desktop
要退出,只需杀死码头码头。并重新启动机器:
sudo docker start ubvnc
然后重新连接VNC。然后退出机器:
sudo docker stop ubvnc
您必须等待几秒钟,等待客户机上的VNC服务器启动,然后才能进行连接。
客人体内的铬不会从菜单开始。如果你试图从命令行启动它,它会解释为什么:
Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
所以只需从CLI运行它:
chromium-browser --no-sandbox
然而,Firefox并不在意。
待办事项:没有音频。——device /dev/snd没有帮助:
如何在Mac OS Yosemite上的Docker容器中播放声音 https://forums.docker.com/t/how-to-get-sound/36527 https://github.com/fcwu/docker-ubuntu-vnc-desktop/issues/49
编辑:他们为它增加了一个部分:https://github.com/fcwu/docker-ubuntu-vnc-desktop/tree/e4922ce92f945fc482994b7a0fd95ca5de7295b3#sound-preview-version-and-linux-only
参见:
如何在Docker映像中打开Ubuntu GUI
测试:
Ubuntu 19.04主机,fcwu/docker-ubuntu-vnc-desktop, dorowu/ Ubuntu -desktop-lxde-vnc镜像id: 70516b87e92d。 Ubuntu 21.10主机:dorowu/ Ubuntu -desktop-lxde-vnc:focal (Ubuntu 20.04)
其他回答
对于使用Nvidia驱动程序的OpenGL渲染,请使用以下图像:
https://github.com/thewtex/docker-opengl-nvidia
对于其他OpenGL实现,确保映像具有与主机相同的实现。
使用docker数据卷,在容器中暴露xorg的unix域套接字是非常容易的。
例如,使用这样的Dockerfile:
FROM debian
RUN apt-get update
RUN apt-get install -qqy x11-apps
ENV DISPLAY :0
CMD xeyes
你可以这样做:
$ docker build -t xeyes - < Dockerfile
$ XSOCK=/tmp/.X11-unix/X0
$ docker run -v $XSOCK:$XSOCK xeyes
当然,这本质上与x转发是一样的。它授予容器对主机上的xserver的完全访问权,因此只有当您信任其中的内容时才建议使用它。
注意:如果你担心安全问题,更好的解决方案是使用强制性或基于角色的访问控制来限制应用程序。Docker实现了相当好的隔离,但它在设计时考虑到了不同的目的。使用AppArmor、SELinux或GrSecurity,它们是为解决您的问题而设计的。
fcwu/docker-ubuntu-vnc-desktop (Ubuntu 18.04, 20.04)
https://github.com/fcwu/docker-ubuntu-vnc-desktop provides a convenient setup. That setup is not minimized. It would be good to minimize it. But I just don't have the time, and that one just works every time I try, so I tend to just use it. On the upside, because it is not minimized, it tends to test more complex programs you might actually to see that they are actually working through the infinitely many pitfalls of Docker. Also, since setups breaks on every guest/host update, a minimization would arguably only work for a limited period until you'd have to reminimize that project again.
要启动它,只需运行:
sudo docker run --name ubvnc -p 6080:80 -p 5900:5900 dorowu/ubuntu-desktop-lxde-vnc:focal
然后在主机上:
visit: http://127.0.0.1:6080/#/ which runs a noVNC more limited JavaScript VNC client run: sudo apt-get install tigervnc-viewer xtigervncviewer :5900 To go into fullscreen mode, hit F8 and click on menu entry, or just F8 followed by T: https://superuser.com/questions/285843/how-do-i-switch-in-out-of-fullscreen-mode-from-the-command-line-in-realvnc You might need to close and reopen the screen after that for the image to get larger. I also tried vinagre, but it was much laggier when scrolling Firefox on YouTube. Inside vinagre, you might want to go into full screen mode to be able to see the full desktop
要退出,只需杀死码头码头。并重新启动机器:
sudo docker start ubvnc
然后重新连接VNC。然后退出机器:
sudo docker stop ubvnc
您必须等待几秒钟,等待客户机上的VNC服务器启动,然后才能进行连接。
客人体内的铬不会从菜单开始。如果你试图从命令行启动它,它会解释为什么:
Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
所以只需从CLI运行它:
chromium-browser --no-sandbox
然而,Firefox并不在意。
待办事项:没有音频。——device /dev/snd没有帮助:
如何在Mac OS Yosemite上的Docker容器中播放声音 https://forums.docker.com/t/how-to-get-sound/36527 https://github.com/fcwu/docker-ubuntu-vnc-desktop/issues/49
编辑:他们为它增加了一个部分:https://github.com/fcwu/docker-ubuntu-vnc-desktop/tree/e4922ce92f945fc482994b7a0fd95ca5de7295b3#sound-preview-version-and-linux-only
参见:
如何在Docker映像中打开Ubuntu GUI
测试:
Ubuntu 19.04主机,fcwu/docker-ubuntu-vnc-desktop, dorowu/ Ubuntu -desktop-lxde-vnc镜像id: 70516b87e92d。 Ubuntu 21.10主机:dorowu/ Ubuntu -desktop-lxde-vnc:focal (Ubuntu 20.04)
OSX (10.13.6, high sierra)
类似于@Nick的答案,但他的解决方案对我不起作用。
首先通过brew install socat安装socat,然后安装XQuartz (https://www.xquartz.org/)
请在评论区(http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/)按照以下步骤进行:
1. in one mac terminal i started:
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
2. and in another mac terminal I ran:
docker run -ti --rm \
-e DISPLAY=$(ipconfig getifaddr en0):0 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
firefox
我也可以从我的debian docker容器中启动CLion。
我通过以下步骤从USB摄像头使用opencv在docker中运行视频流:
Let docker access the X server xhost +local:docker Create the X11 Unix socket and the X authentication file XSOCK=/tmp/.X11-unix XAUTH=/tmp/.docker.xauth Add proper permissions xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - Set the Qt rendering speed to "native", so it doesn't bypass the X11 rendering engine export QT_GRAPHICSSYSTEM=native Tell Qt to not use MIT-SHM (shared memory) - that way it should be also safer security-wise export QT_X11_NO_MITSHM=1 Update the docker run command docker run -it \ -e DISPLAY=$DISPLAY \ -e XAUTHORITY=$XAUTH \ -v $XSOCK:$XSOCK \ -v $XAUTH:$XAUTH \ --runtime=nvidia \ --device=/dev/video0:/dev/video0 \ nvcr.io/nvidia/pytorch:19.10-py3
注意:当你完成项目时,返回默认值的访问控制- xhost -local:docker
更多细节:使用GUI的Docker
图片来源:使用Tensorflow、OpenCV和Docker进行实时和视频处理对象检测