GIU Application on Docker

saurabh kharkate
5 min readMay 10, 2021
Running GUI Applications in Docker — Firefox, Nautilus File Manger. |  LaptrinhX

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. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that the machine might have that could differ from the machine used for writing and testing the code.

In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on and only requires applications to be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.

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 we run GUI Application on Docker?

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.

Types of applications (usually services) that you can containerize:

  • Applications that run as a Background Service (like a Database, WebServer, etc)
  • GUI Applications that run in the foreground.

we are going to see the second option

X Window System/ X:

  • X11 is the current version of the X Window System.

X provides the basic framework for a GUI environment:

Graphics Interface windows on the display device and interacting with a mouse and keyboard. X does not mandate the user interface — this is handled by individual programs. As such, the visual styling of X-based environments varies greatly; different programs may present radically different interfaces.on Unix-like operating systems.

For a GUI Application to run, we need to have an XServer which is available as part of every Linux Desktop Environment.

Run the following command to see the X Server and X Client running on your Linux Machine:

# ps -aux | grep X

Let’s launch GUI application on Docker.

Step 1 : Start the Docker service.

# systemctl restart docker

Step 2: 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.

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.

# mkdir /ws26# vim Dockerfile
# sudo docker build -t :v1

we can push the image from docker hub

you can pull this image using below command# docker pull saurabh05sk/myrepo:docker-gui:v1

Step 3: While launching containers we need to specify three things.

  • 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.
--net=host
  • Now Launch Conatainers with below commands.
# docker run --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" gui-app:v1 firefox


# docker run --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" gui-app:v1 gedit
  • Firefox run successfully
  • Gedit run successfully.

We can see output it works succesfully..

!!! Task completed Successfully !!!! 😃😃😉

☘☘Keep Sharing!!! , Keep Learning!!! ☘☘

🙏🙏Thanks for Reading 🙏🙏

--

--