Run GUI Application On Docker
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB2YyUbldzLNEWbFmLpJUXCjr42qqz3WMZo_TAb__dU6rDsrZ2X_g-dIhQsSyBTnOXEgB9UjhgPYHR0Ha6AzWNhXIiOIPXRCs5XTE92rV5QfvkmicE3lv9e-ifAmeQXY7Y_7NsfEMk16w/s16000/GUI.jpg)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif7ZLZ4UfSmeE9m7duqhKHH-y9DiHp13AuPByZAY8n7mptZcU9YvJ7W4GA3RIHEmU3833knjrw7JbIZEtVewHx1gHpWCCZmq9jIHBuVPl2N0np5ilx_9aqfkfkPsmAl5F_oYA9OAY5NLA/s16000/f55e8059ea945abfd6804b887dd4a0af.gif)
The X Window System (X11, or simply X) is a windowing system for bitmap displays, common on Unix-like operating systems.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdTPeOmOUx1IH_56fHXDzOWos6CQe92ADiRC_MGTCbA8aWtc0Cwkk4deu0gEt9oax0qBu0kQp-99z0-n-ZMp0x0ZyBJsoUfdVwyvTTVgdWfCxdbVyXfnqKGdeqJn0hu34n5dLI5Wzbkos/s16000/logo.png)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_rxfdyrpwG_GwOg7XByurhU6sQNKzUp_R9_Q8Xk_SNtrFl3rRbpF1l3rivnEaWY1_UhiuyXdPAztAbkGrTd4PWUMJpQtzI49GCZ4HNRykbZ1JzMnypX8QuS20rQ3oCM-3Hd8E6lHAlSo/w238-h400/1_pV6cBlFplTa7YOSLDk5JWg.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3h64TcK8MC1nEiQRqRbaBZc8FtLRDokkg8KXj_IFHzR8U-iyl24eIJwwtXN2IdnqFI8VebchU8_GosCKlGFioxL4H7Yjt3C1Rb2gTal5qIwtF3689eznuO-wog6R3wofnUGsv2UUnd_M/s16000/carbon.png)
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!!!!
Very much informative
ReplyDeletethanks
Delete