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

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

问题描述

问题

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

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.

问题是我曾尝试使用 Chef,但实际维护 Chef 知识和技能需要付出很多努力(我们没有专门的 Ops 人员)而且如果某个第三方存储库,Chef recipe 可能会失败不再可用(这是一个主要的障碍).

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).

我想尝试使用Docker来解决问题,但我仍然不知道是否可以设置允许某些基于 GUI 的软件运行的图像/容器.

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.

问题

是否可以使用 Docker 为基于 GUI 的应用程序 (PyQt/QT) 提供开发/生产环境?如果是,那么解决这个问题的第一步是什么?

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?

推荐答案

目前这个问题没有答案,但它在 Google 上的排名非常高.其他答案大部分是正确的,但有一些警告,我已经学会了艰难的方法,我想省去其他人的麻烦.

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.

Nasser Alshammari 给出的答案是在 Docker 容器内运行 GTK 应用程序的最简单(也是最快)的方法 - 只需将 X 服务器的套接字挂载为 Docker 卷并告诉 Docker 使用它.

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

(我还建议传递 -u 标志,因为以 root 身份运行 X11 应用程序并不总是有效,通常不推荐,尤其是 分享会话时).

(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).

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

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).

但是,您的回答专门询问了 PyQT.原来Qt不支持这种方式共享X会话(或至少支持得不好).

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).

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

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

我说可能"是因为我还没有用足够多的 Qt 应用程序测试这种方法来确定,或者深入研究 Qt 源代码以找出不支持的原因.YMMV,您可能会很幸运,但是如果您希望从 Docker 容器中运行基于 Qt 的应用程序,您可能不得不采用老式"方法,并且要么

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. 在容器内运行 sshd,开启 X11 转发,然后使用 ssh -X(更安全)或 ssh -Y(安全性较低,在您完全信任容器化应用程序时使用).

  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).

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

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.

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

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