如何在Ubuntu 18.04上使用Docker和Caddy远程访问GUI应用程序

介绍 (Introduction)

Even with the growing popularity of cloud services, the need for running native applications still exists.

即使云服务越来越流行,仍然需要运行本机应用程序。

By using noVNC and TigerVNC, you can run native applications inside a Docker container and access them remotely using a web browser. Additionally, you can run your application on a server with more system resources than you might have available locally, which can provide increased flexibility when running large applications.

通过使用noVNCTigerVNC ,您可以在Docker容器内运行本机应用程序,并使用Web浏览器远程访问它们。 此外,您可以在具有比本地可用资源更多的系统资源的服务器上运行应用程序,这可以在运行大型应用程序时提供更大的灵活性。

In this tutorial, you’ll containerize Mozilla Thunderbird, an email client, using Docker. Afterward, you’ll secure it and provide remote access using the Caddy web server.

在本教程中,您将使用Docker容器化Mozilla Thunderbird (电子邮件客户端)。 之后,您将保护它并使用Caddy Web服务器提供远程访问。

When you’re finished, you’ll be able to access Thunderbird from any device using just a web browser. Optionally, you’ll also be able to locally access the files from it using WebDAV. You’ll also have a fully self-contained Docker image that you can run anywhere.

完成后,您将可以仅使用Web浏览器从任何设备访问Thunderbird。 (可选)您还可以使用WebDAV从本地访问文件。 您还将拥有一个完全独立的Docker映像,可以在任何地方运行。

先决条件 (Prerequisites)

Before you begin this guide, you’ll need the following:

在开始本指南之前,您需要满足以下条件:

第1步-创建supervisord配置 (Step 1 — Creating the supervisord Configuration)

Now that your server is running and Docker is installed, you are ready to begin configuring your application’s container. Since your container consists of multiple components, you need to use a process manager to launch and monitor them. Here, you’ll be using supervisord. supervisord is a process manager written in Python that is often used to orchestrate complex containers.

现在您的服务器正在运行,并且已经安装了Docker,您可以开始配置应用程序的容器了。 由于您的容器包含多个组件,因此您需要使用流程管理器来启动和监视它们。 在这里,您将使用supervisordsupervisord是用Python编写的过程管理器,通常用于编排复杂的容器。

First, create and enter a directory called thunderbird for your container:

首先,为您的容器创建并输入一个名为thunderbird的目录:

  • mkdir ~/thunderbird

    麦克迪尔〜/雷鸟
  • cd ~/thunderbird

    cd〜/雷鸟

Now create and open a file called supervisord.conf using nano or your preferred editor:

现在,使用nano或您喜欢的编辑器创建并打开一个名为supervisord.conf的文件:

  • nano supervisord.conf

    纳米主管

Now add this first block of code into supervisord.conf, which will define the global options for supervisord:

现在,将这第一段代码添加到supervisord.conf ,这将为supervisord.conf定义全局选项:

~/thunderbird/supervisord.conf
〜/ thunderbird / supervisord.conf
[supervisord]
nodaemon=true
pidfile=/tmp/supervisord.pid
logfile=/dev/fd/1
logfile_maxbytes=0

In this block, you are configuring supervisord itself. You need to set nodaemon to true because it will be running inside of a Docker container as the entrypoint. Therefore, you want it to remain running in the foreground. You also are setting pidfile to a path accessible by a non-root user (more on this later), and logfile to stdout so you can see the logs.

在此块中,您将配置supervisord本身。 您需要将nodaemon设置为true因为它将在Docker容器内作为入口运行。 因此,您希望它继续在前台运行。 您还将pidfile设置为非root用户可访问的路径(稍后将对此进行详细介绍),而将logfile为stdout以便可以查看日志。

Next, add another small block of code to supervisord.conf. This block starts TigerVNC, which is a combined VNC/X11 server:

接下来,将另一小段代码添加到supervisord.conf 。 此块启动TigerVNC,它是组合的VNC / X11服务器:

~/thunderbird/supervisord.conf
〜/ thunderbird / supervisord.conf
...
[program:x11]
priority=0
command=/usr/bin/Xtigervnc -desktop "Thunderbird" -localhost -rfbport 5900 -SecurityTypes None -AlwaysShared -AcceptKeyEvents -AcceptPointerEvents -AcceptSetDesktopSize -SendCutText -AcceptCutText :0
autorestart=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

In this block, you are setting up the X11 server. X11 is a display server protocol, which is what allows GUI applications to run. Note that in the future it will be replaced with Wayland, but remote access is still in development.

在此块中,您将设置X11服务器。 X11是显示服务器协议,它允许GUI应用程序运行。 请注意,将来它将被Wayland取代,但是远程访问仍在开发中。

For this container, you are using TigerVNC and its built-in VNC server. This has a number of advantages over using a separate X11 and VNC server:

对于此容器,您正在使用TigerVNC及其内置的VNC服务器。 与使用单独的X11和VNC服务器相比,这具有许多优点:

  • Faster response time, as the GUI drawing is done directly to the VNC server rather than being done to an intermediary framebuffer (the memory which stores the contents of the screen).

    响应时间更快,因为GUI绘制直接对VNC服务器完成,而不是对中间帧缓冲区(存储屏幕内容的内存)进行。
  • Automatic screen resizing, which allows the remote application to automatically resize to fit the client (in this case, your web browser window).

    自动调整屏幕大小,允许远程应用程序自动调整大小以适合客户端(在这种情况下,您的Web浏览器窗口)。

If you wish, you can change the argument for the -desktop option from Thunderbird to something else of your choosing. The server will display your choice as the title of the webpage used to access your application.

如果愿意,可以将-desktop选项的参数从Thunderbird更改为您选择的其他选项。 服务器将您的选择显示为用于访问您的应用程序的网页的标题。

Now, let’s add a third block of code to supervisord.conf to start easy-novnc:

现在,让我们向supervisord.conf添加第三段代码以启动easy-novnc

~/thunderbird/supervisord.conf
〜/ thunderbird / supervisord.conf
...
[program:easy-novnc]
priority=0
command=/usr/local/bin/easy-novnc --addr :8080 --host localhost 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值