在Docker容器中使用VNCserver + GUI应用程序+虚拟显示 [英] Using VNCserver + GUI application + Virtual Display in Docker container

查看:709
本文介绍了在Docker容器中使用VNCserver + GUI应用程序+虚拟显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在docker容器中运行firefox(或任何图形应用程序)。

I would like to run firefox (or any graphical application) inside docker container.

我的要求:启动容器时,我应该创建一个虚拟显示器,先启动VNC服务器,再启动GUI应用程序。这意味着在容器成功启动后,我可以通过VNC客户端连接到在容器内运行的GUI应用程序。关闭应用程序时,容器应自动停止。

My requirement: When I start the container, I should be creating a virtual display, starting VNC server and then the GUI application. This means after the container is successfully started, I can connect to the GUI application running inside the container via VNC client. When I close the application, the container should automatically stop.

尝试1:
我从此处的示例开始 https://hub.docker.com/r/devopsil/vnc-firefox/~ / dockerfile /
在此示例中,开发人员通过CMD启动vnc服务器并使其永远运行。他将firefox放在.rc文件中,以便在容器启动时启动。如果通过VNC客户端连接,则会看到Firefox,并且按预期关闭Firefox或断开VNC会话不会停止容器。

Attempt 1: I started with the example here https://hub.docker.com/r/devopsil/vnc-firefox/~/dockerfile/ In this example the developer starts the vnc server via CMD and keeps it running forever. He puts the firefox as part of .rc file so it starts when the container starts. If you connect via VNC client, you can see firefox and as expected closing firefox or disconnecting the VNC session does not stop the container.

尝试2:
我对Dockerfile进行了如下调整。仅更改了最后一行(用ENTRYPOINT替换了CMD,并删除了 forever标志)

Attempt 2: I tuned the Dockerfile as follows. Changed only the last line (replaced CMD with ENTRYPOINT and removed the "forever" flag")

ENTRYPOINT ["/usr/bin/x11vnc", "-usepw", "-create"]

重建并运行容器 docker运行--rm -p 5900现在具有不同的行为:
容器启动,通过VNC客户端的连接正常,firefox在几秒钟后打开(等待消息显示器上显示扩展名RANDR丢失:20),并且容器在关闭vnc连接后自动停止。

Rebuilding and running the container "docker run --rm -p 5900 " had a different behaviour now: container starts, connection via VNC client worked, firefox opened after a few seconds (wait after the message "extension RANDR missing on display :20") and the container stopped automatically after closing the vnc connection.

尝试3:
然后,我创建了一个bash脚本来启动vncserver和firefox并更改了Dockerfile,以将该脚本文件复制到映像中,并将脚本作为入口点。但是我收到类似于未设置显示变量的错误

Attempt 3: Then I created a bash script to start the vncserver and firefox and changed the Dockerfile to copy this script file inside the image and made the script as the entry point. But I got the error similar to "Display variable not set"

#!/bin/bash
/usr/bin/x11vnc -forever -usepw -create &
firefox

尝试4:
通过docker run命令传递了DISPLAY变量,但该错误无法打开显示。

Attempt 4: So I passed the DISPLAY variable via the docker run command but then the error is cannot open display.

问题:我不知道该怎么喜欢由vncserver标志将 -create创建为Firefox的虚拟显示。请让我知道在容器启动时启动GUI应用程序并在GUI应用程序关闭时自动停止容器的最佳方法是什么。我相信dockerfile中的ENTRYPOINT应该设置为firefox。谢谢您的帮助。

Question: I don’t know how to like the virtual display created by the vncserver flag "-create" to the firefox. Please let me know what would be best way to start the GUI application when the container starts and automatically stop the container when the GUI application is closed. I believe the ENTRYPOINT in dockerfile should be set to firefox. Thanks for your help.

我已经看到了这个 https://blog.jessfraz.com/post/docker-containers-on-the-desktop/ ,但这对我没有用,因为我想远程访问该应用程序

I have seen this https://blog.jessfraz.com/post/docker-containers-on-the-desktop/ but this is of no use to me as I want to access the application remotely via VNC.

推荐答案

我设法找到了解决方案:

I managed to found the solution:

如下更改了 Attempt 3 中的脚本,如下所示

Changed the script in Attempt 3 above as follows worked

!/bin/bash

Xvfb :1 -screen 0 800x600x16 &
/usr/bin/x11vnc -display :1.0 -usepw &
DISPLAY=:1.0
export DISPLAY
firefox

干杯。

这篇关于在Docker容器中使用VNCserver + GUI应用程序+虚拟显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆