Run GUI Applications Over Docker
Learn docker basics and run a GUI app over docker
The title of the article speaks for itself. Before moving ahead towards the practical let us get know-how about what are terms used in the title.
What is Docker?
Let’s have a quick look at what is Docker.
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.
Docker is capable of creating images that can be used anytime in later stages. Docker is run over the base operating system, it mostly supports the non-GUI application. It gives you a black screen known as CLI.
What is a GUI application?
The term GUI here stands for Graphical User interface. That is it acts as an interface between the user and the system and communicates through graphical visuals unlike giving text commands.
Can you run a GUI application over Docker?
YES.
Yes, you can. As docker launches a container (consider it as a new operating system) over the base os (Linux for example) it provides you CLI ( Command Line interface) by default to the user. For launching GUI application we need certain Display drivers present in the local system to be shared with the container.
Techno-freaks mostly use CLI for their work but using a little graphics will not harm for sure. Let's add fun to your docker.
Building an Image:
The first step includes building an image using DockerFile. Here we will install the software requirements for GUI. Also, install the application you want to have a GUI for.
Create a DockerFile
Here we will run two GUI applications: Firefox and gedit. In addition, we have installed the libcanberra-gtk2: (Libcanberra is an implementation of the XDG Sound Theme and Name Specifications, for generating event sounds) and packagekit-gtk3-module: (PackageKit is a system designed to make installing and updating software on your computer easier. The primary design goal is to unify all the software graphical tools)
Build the file
The next step is to build the image by attaching your docker hub account username with it. Use the command in the red box to build your image.
You can push the image to your docker hub account and pull it whenever required.
The image is available in the base system. The next step is to launch a container with this image following some additional arguments.
Run the container:
To run the container we add the arguments as any GUI Application requires to have an XServer : (X Window System (also known as X11, or simply X) is a client/server windowing system for bitmap displays.) which is available as part of every Linux Environment, not within a docker container
share the Host’s XServer with the Container by creating a volume
--volume="$HOME/.Xauthority:/root/.Xauthority:rw"
share the Host’s DISPLAY environment variable to the Container
--env="DISPLAY"
run container with host network driver with
--net=host
This command is followed by a warning which can be ignored.
Output
After running the above command we land up in the docker container with the GUI application firefox being opened.
You can launch the gedit as well because we build it in the image. gedit is a text editor with a graphical interface like notepad.
Hope you enjoyed this quick article and got to learn something new. Leave a few claps to show some love and stay tuned for more articles.