GUI APPLICATION ON DOCKER CONTAINER:-
WHAT IS DOCKER?
Docker is a tool that uses OS-level virtualization to deliver software in packages called containers.
ADVANTAGES OF DOCKER:-
Docker containers provide a way to build and deploy applications that is easier to:-
- Assemble
- Maintain
- Manage
Therefore, Docker containers are stateless. The resources used by docker containers are very minimal. Docker containers provide high speed. They are easy to scale.
WHAT IS DOCKERFILE?
DOCKERFILE is a simple text file where instead of writing every single command on CLI and run it manually to configure something we can put it in one text file i.e. kind of automation and build the image using it and then able to configure anything very easily. The docker file consists of environmental variables, network port, and other components.
WHAT IS 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.
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.
CAN YOU RUN A GUI APPLICATION OVER DOCKER?
YES, you can.
As docker launches a container (consider it as a new operating system) over the baseOS (Linux for ex.) 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.
So, it means if we want to run GUI applications on a docker container then we need a display, as the container is not connected to the display. We need to connect the display of baseOS.
THERE ARE TWO TYPES OF APPLICATIONS:-
- Background
- Foreground
The foreground applications require a GUI (For example Gedit, Firefox, etc.)
Foreground applications requires Xserver.
WHAT IS Xserver?
X is an application that manages one or more graphical displays and inputs like (keyboard, mouse, webcam, etc.) connected to the computer. X is the GUI protocol for Linux/Unix system.
So, Services communicate with the Xserver to display a graphical interface and receive input from the user and the Xserver clients can be on the remote system.
Here, We are going to use a remote system as a docker container.
The Xserver provides the following basic types of services:-
- Input handling
- Window services
- Graphics
- Text and Fonts
Task Description:-
📌 GUI container on the Docker:-
🔅 Launch a container on docker in GUI mode.
🔅 Run any GUI software on the container.
Let's start...
First check the docker service status that should be active.
STEP 1:- Create a Dockerfile into the workspace /ws26 and build the image using it.
We are going to launch firefox and gedit on container having some module dependenies like we have installed the libcanberra-gtk2 and PackageKit-gtk3-module.
Libcanberra is an implementation of the XDG Sound Theme and Name Specifications, for generating event sounds.
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.
vim Dockerfile
sudo docker build -t gui-app:v1
We can also push the image into docker hub.
Dockerhub link:- https://hub.docker.com/repository/docker/pk2507/gui-app
STEP 2:- Now run the containers for the applications.
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.
While launching containers we need to specify three things.
1) share the Host’s XServer with the Container by creating a volume.
--volume="$HOME/.Xauthority:/root/.Xauthority:rw"
2) share the Host’s DISPLAY environment variable to the Container.
--env="DISPLAY"
3) run container with host network driver.
--net=host
The location of Xserver is:-
Now launch the containers with GUI applications (Chrome) i.e. firefox and gedit.
sudo docker run --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" gui-app:v1 firefox sudo docker run --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" gui-app:v1 gedit
STEP 3:- Output of both the applications.
FIREFOX:-
GEDIT (Text Editor):-
And, thus objective of task has been completed.
Thanks for reading my article!! 😇
KEEP LEARNING. KEEP SHARING.
Very well written. We can use docker containers on different platforms, one of them being Raspberry Pi.
Great work
good one Prachika Kanodia