Running GUI Applications in Docker
By Fraser Adams
Copyright 2020 Fraser Adams. All rights reserved.
While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk.
If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
Contents
1.1.
1.2.
1.3.
2.1.
2.2.
2.2.1.
2.2.2.
2.2.3.
2.2.4.
2.2.5.
2.3.
2.4.
2.5.
2.6.
2.7.
2.8.
3.1.
3.2.
3.2.1.
3.2.2.
3.2.3.
3.2.4.
3.3.
4.1.
4.1.1.
4.1.2.
4.2.
4.2.1.
4.2.2.
4.2.3.
4.3.
4.3.1.
4.3.2.
4.3.3.
4.3.4.
4.3.5.
4.4.
4.4.1.
4.4.2.
4.4.3.
4.4.4.
4.5.
4.5.1.
4.5.2.
4.6.
4.6.1.
4.7.
4.7.1.
4.7.2.
4.7.3.
4.8.
4.8.1.
4.8.2.
5.1.
5.2.
5.2.1.
5.2.2.
5.2.3.
5.2.4.
5.2.5.
5.2.6.
5.3.
5.3.1.
5.3.2.
5.3.3.
5.3.4.
5.3.5.
5.3.6.
5.4.
5.4.1.
5.4.2.
5.4.3.
5.4.4.
5.4.5.
5.4.6.
5.4.7.
5.4.8.
5.4.9.
5.5.
5.5.1.
5.5.2.
5.5.3.
5.6.
5.6.1.
5.6.2.
5.6.3.
5.6.4.
5.7.
5.7.1.
5.7.2.
5.7.3.
5.7.4.
6.1.
6.1.1.
6.2.
6.2.1.
6.2.2.
6.3.
6.3.1.
6.4.
6.4.1.
6.4.2.
6.5.
6.5.1.
6.5.2.
6.5.3.
6.5.4.
6.6.
6.6.1.
6.6.2.
6.6.3.
6.7.
6.8.
6.8.1.
6.8.2.
6.8.3.
6.9.
6.9.1.
6.9.2.
6.9.3.
7.1.
7.2.
7.3.
7.4.
7.5.
7.6.
7.7.
7.8.
8.1.
8.1.1.
8.1.2.
8.2.
8.3.
8.4.
8.5.
8.5.1.
8.5.2.
9.1.
9.2.
9.3.
9.4.
9.5.
9.6.
10.1.
10.2.
10.3.
10.4.
11.1.
11.1.1.
11.1.2.
11.1.3.
11.1.4.
11.2.
11.2.1.
11.2.2.
11.2.3.
11.3.
11.3.1.
11.3.2.
11.3.3.
11.3.4.
11.3.5.
11.3.6.
11.3.7.
11.3.8.
11.4.
11.4.1.
11.4.2.
11.4.3.
1 Introduction
1-1 The Purpose of this Book
This book provides a comprehensive step-by-step guide to packaging and running GUI applications as Docker containers. The book sets the scene with some simple and well-known X11 applications hosted locally, before tackling more advanced topics such as enabling GPU acceleration in containers to support OpenGL applications. The book also covers several less-frequently discussed topics such as remote accelerated rendering via VirtualGL to enable Cloud hosting of high-end GUI applications, D-bus integration, AppArmor, real-time scheduling, and running full virtual desktops in containers.
Although this book covers many advanced Docker concepts it is not a tutorial on Docker and some familiarity with Docker would be useful, but not essential, as all of the examples come complete with detailed explanation and the command line instructions necessary to run them.
As the point of the book is to illustrate the concepts by example the source code is, of course, freely available and Apache 2.0 Licensed on GitHub.
To run the examples a reasonably modern Linux distribution capable of running Docker and an X11 capable desktop are required. The OpenGL applications require either Nvidia or Open Source Mesa drivers although some OpenGL 2.1 applications should work with the VirtualBox virtual GPU.
1-2 What is Docker
Docker is a technology that provides a form of Operating System level virtualisation known as containerisation . Docker uses the resource isolation features of the Linux kernel such as cgroups , namespaces , and union mount filesystems to allow multiple isolated user space instances or containers to run within a single physical (or virtual) Linux instance with lower overhead than full virtual machines.
Containers may also usefully be thought of as an application abstraction that allows application code, dependencies and configuration to be packaged together providing a clean contract with the underlying operating system, offering maximum portability between execution environments.
Multiple containers may be run on the same physical or virtual machine, each sharing the Operating System kernel with other containers and each running as isolated processes in user space. By packaging code, configuration and other dependencies containers also enable improved efficiencies and consistency in the code delivery pipeline from development to production, improving productivity and reliability.
Because containers typically impose little or no overhead using Docker allows for far greater resource utilisation than full virtual machines allowing high levels of server consolidation and multi-tenancy. The low overhead of containers facilitates microservice architectures and elastic scale-out, paving the way for PaaS and Cloud migration.
1-3 Why Run GUI Applications in Docker
As the popularity of Docker explodes and it becomes one of the leading application deployment platforms , more and more people are recognising the benefits that the powerful application packaging features of containers can bring. Typically however, the vast majority of Docker examples on the web tend to focus on containerising server applications and relatively few people currently seem to be considering use-cases beyond packaging servers and services.
It is actually perfectly possible though to run full GUI applications in Docker containers, that is to say to run native graphical or video applications as opposed to applications that simply expose an HTML web interface, so perhaps the question to ask is why bother.
That question is fair enough, many people see Docker in the context of large data centre deployments or software development and DevOps, and on the desktop things like cluster environments and application portability might not appear particularly important. On the other hand Docker can help to solve many problems, for example: packaging applications in a platform agnostic way such that they just work irrespective of the Linux distribution they are being deployed to; allowing multiple different versions of an application to be deployed simultaneously; enabling untrusted applications to be tested more safely and cleanly removed; enabling licences to be more effectively managed; enabling better utilisation of high-end GPU rendering resources, etc.