Latest Updates

Run GUI Application On Docker


Docker

Docker is a set of the platform as service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels.



X Window system

The X Window System (X11, or simply X) is a windowing system for bitmap displays, common on Unix-like operating systems.


X provides the basic framework for a GUI environment: drawing and moving 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.





display protocol, X was specifically designed to be used over network connections rather than on an integral or attached display device. X features network transparency, which means an X program running on a computer somewhere on a network (such as the Internet) can display its user interface on an X server running on some other computer on the network. The X server is typically the provider of graphics resources and keyboard/mouse events to X clients, meaning that the X server is usually running on the computer in front of a human user, while the X client applications run anywhere on the network and communicate with the user’s computer to request the rendering of graphics content and receive events from input devices including keyboards and mice.

For more info, you can read the wiki:

https://en.wikipedia.org/wiki/X_Window_System

Why we Need GUI on the Docker Container??

let’s say you are building an application that has GUI and deploying it on a docker container and right now the application is in testing so there is no infrastructure like production.

Now, If you want that GUI application to display the user interface screen on your local machine while running the application inside the docker container, you will have to connect it with the display but as you know docker containers don’t have a graphical interface so we need a display that will show our application’s GUI and this is the use case where x11 server will help to show GUI on remote display with all normal functions like the mouse, keyboard.

Let’s Take the Example of the firefox browser

without going into many complicated things Let suppose, you want to run the firefox browser inside a Docker container. but as we discussed docker not run GUI application so we need to get help x11 server to connect to the remote display here remote display is the docker host machine on which docker is running. by default docker not provide such an official image that gives you a browser so we need to create one.

Note: you can use “Gedit” and other GUI-based applications as well I am just using firefox just edit the image according to you and build it.

following is the GitHub link that will provide you code.

GitHub:

or you can pull directly from my repository:

https://hub.docker.com/r/venkatesh14/mozilla-firefox

Now we will launch our container from this but we need to provide some arguments that will help us to get the display

Now, let’s launch container

as you can see we launched a docker container using the above configurations it taking the help of the host machine and x11 server to display the Firefox browser you can see on the browser it is a centos project and it is because our image created from centos.

Note: I used ‘rm’ to remove the container automatically after stopped it is optional.

Conclusion:

In this way, we have seen that for some custom requirements we can use custom build images and using some Linux features we can use GUI applications in Docker containers.

Hope this blog is helpful to you!!!!


2 comments: