Docker用于基于GUI的环境? [英] Docker for GUI-based environments?

查看:642
本文介绍了Docker用于基于GUI的环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



我有一组作为企业Web应用程序一部分的客户机。每个机器运行相同的软件,这是一个连接到服务器的基于PyQT的Web客户端。这个客户端软件定期更新,我想要一些配置/配置工具,允许在每个机器上拥有相同的环境,从而在每个客户端的机器上轻松部署和配置软件。

$问题是我尝试使用厨师,但实际维护厨师的知识和技能(我们没有一个专门的Ops家伙)需要付出很多努力,而且厨师食谱如果某些第三方存储库不再可用(这是一个主要的阻塞),则可能会失败。



我想尝试Docker解决问题,但我仍然不知道,如果可以设置允许一些基于GUI的软件运行的图像/容器。



问题 p>

是否可以使用Docker来开发/生产环境对于基于GUI的应用程序(PyQt / QT)?如果是的话,接下来的第一步是什么?

解决方案

目前这个问题没有回答,在Google上排名。其他答案大部分是正确的,但是我已经学到了很多困难的一些注意事项,我想拯救别人的麻烦。



纳赛尔·阿尔沙马里给出的答案是在Docker容器中运行GTK应用程序的最简单(最快速的)方法 - 只需将X服务器的套接字作为Docker卷进行安装,并告诉Docker使用它。

  docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY = unix $ DISPLAY TheImage 

(我还建议将 -u< username-within-container> 标志传递作为root用户的X11应用程序并不总是可以正常工作,而且在共享会话时通常不推荐使用,特别是。



这将适用于 xterm 以及基于GTK的应用程序。例如,如果您尝试使用Firefox(这是基于GTK的),它将会工作(请注意,如果您已经在主机上运行Firefox,它将在主机中打开一个新窗口,而不是打开一个新的Firefox实例从容器内)。



然而,您的答案专门询问PyQT。 事实证明,Qt不支持以这种方式共享X会话(或至少不支持它)



如果您尝试以这种方式运行基于QT的应用程序,您可能会收到如下错误:

  X错误:BadAccess(尝试访问私人资源被拒绝)10 
扩展名:140(MIT-SHM)
Minor操作码:1(X_ShmAttach)
资源ID:0x12d
X错误:BadShmSeg(无效共享段参数)148
扩展名:140(MIT-SHM)
次要操作码:5 (X_ShmCreatePixmap)
资源ID:0xb1
X错误:BadDrawable(无效的Pixmap或Window参数)9
主要操作码:62(X_CopyArea)
资源ID:0x2c0000d
X错误:BadDrawable(无效的Pixmap或Window参数)9
主要操作码:62(X_CopyArea)
资源ID:0x2c0000d

我说可能,因为我没有使用足够的Qt应用程序来测试这种方法,以确保,或者将Qt源代码挖掘出来,以确定为什么不支持这一点。 YMMV,您可能会很幸运,但如果您希望在Docker容器内运行基于Qt的应用程序,则可能需要执行旧式方法,


  1. 在容器内运行sshd,打开X11转发,然后使用 ssh -X (更安全)或 ssh -Y (安全性较低,仅使用 ,如果您完全信任容器化应用程序) / p>


  2. 在容器内运行VNC,并使用VNC客户端从主机连接到它。


在这两个选项之间,我会推荐第一个,但看看哪个最适合您的情况。


Problem

I have a set of client machines that are a part of an enterprise web application. Each machine runs identical software, which is a PyQT-based web client that connects to a server. This client software is updated regularly and I would like to have some configuration/provisioning tool that allows to have the same environment on each machine and hence provide easy deployment and configuration of the software onto each of the clients' machines.

The problem is that I have tried to use Chef, but it takes a lot of effort to actually maintain Chef knowledge and skills (we do not have a dedicated Ops guy) and moreover a Chef recipe can fail if some third party repository is no longer available (this is a main stopper).

I would like to try Docker to solve the problem, but I still do not know if it is possible to set up images/containers that allow for some GUI based software to operate.

Question

Is it possible to use Docker to have a development/production environment for a GUI-based application (PyQt/QT)? If yes, what would be the first steps to approach that?

解决方案

Currently this question is not answered, but it is very highly ranked on Google. The other answers are mostly correct, but with some caveats that I have learned the hard way, and I would like to save others trouble.

The answer given by Nasser Alshammari is the simplest (and fastest) approach to running GTK applications inside a Docker container - simply mount the socket for the X server as a Docker volume and tell Docker to use that instead.

docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY TheImage

(I would also recommend passing the -u <username-within-container> flag, as running X11 applications as root does not always work, and is generally not recommended, especially when sharing sessions).

This will work for applications such as xterm, as well as GTK-based applications. For example, if you try this with Firefox (which is GTK-based), it will work (note that if you are already running Firefox on the host, it will open a new window in the host rather than open a new instance of Firefox from within the container).

However, your answer asks about PyQT specifically. It turns out that Qt does not support sharing of X sessions in this way (or at least does not support it well).

If you try running a QT-based application this way, you will probably get an error like the following:

X Error: BadAccess (attempt to access private resource denied) 10
  Extension:    140 (MIT-SHM)
  Minor opcode: 1 (X_ShmAttach)
  Resource id:  0x12d
X Error: BadShmSeg (invalid shared segment parameter) 148
  Extension:    140 (MIT-SHM)
  Minor opcode: 5 (X_ShmCreatePixmap)
  Resource id:  0xb1
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x2c0000d
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
  Major opcode: 62 (X_CopyArea)
  Resource id:  0x2c0000d

I say "probably" because I have not tested this approach with enough Qt applications to be sure, or dug into the Qt source code enough to figure out why this is not supported. YMMV, and you may get lucky, but if you are looking to run a Qt-based application from within a Docker container, you may have to go the "old-fashioned" approach and either

  1. Run sshd within the container, turn on X11 forwarding, and then connect to the container using ssh -X (more secure) or ssh -Y (less secure, used only if you fully trust the containerized application).

  2. Run VNC within the container, and connect to it from the host with a VNC client.

Between those two options, I would recommend the first, but see which works best for your situation.

这篇关于Docker用于基于GUI的环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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