GUI APP IN DOCKER CONTAINER — FIREFOX
Umesh Tyagi
DevOps Engineer | Terraform, Kubernetes, CI/CD, Ansible, Python, Podman, AWS, Github Actions |
What is Docker?
Docker is a software platform for building applications based on containers — small and lightweight execution environments that make shared use of the operating system kernel but otherwise run in isolation from one another. It allows 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. 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.
Types of applications that you can containerize your application:
- Applications that run as a Background Service (like a Database, WebServer, etc)
- GUI Applications that run in the foreground.
Today, we are going to see the second option:
X Window System/ X: X11 is the current version of the X Window System. X is an application that manages one or more graphics displays and one or more input devices (keyboard, mouse, etc.) connected to the computer. It works as a server and can run on the local computer or on another computer on the network. 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
I am providing two options for launch a runnable containerize application with GUI firefox
The first one is you can download my image and run the docker container directly using the following command: in below command <1703706/firefox> is my docker image that is uploaded in the docker hub repository.
docker run -it — rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix — net=host 1703706/firefox
The second one is you follow the given below steps to create your own image using the docker file and launch the docker container.
Dockerfile to build an image with a sample GUI application (Firefox):
cat Dockerfile
FROM centos:7 RUN yum install -y firefox RUN yum install -y libcanberra-gtk2 RUN yum install -y PackageKit-gtk3-module CMD [“/usr/bin/firefox”]
Creating an image for firefox using the docker build command
docker build -t <image_name> <path/to/dockerfile>
While we launching the container we have used some new vocabularies. Let’s understand what are they?
They are:
Within a Container, we don’t have any XServer — so we will:
Mount the X11 socket residing in /tmp/.X11-unix on your local machine into /tmp/.X11-unix in the container.
-v /tmp/.X11-unix:/tmp/.X11-unix
We will share the Host’s DISPLAY environment variable to the Container
-e DISPLAY=$DISPLAY
And run the container with the host network driver with
— net=host
Now, Run the docker container with the image which we have created earlier.
docker run -it — rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix — net=host <image_name>
You should see the firefox GUI application now displayed on your Host OS Desktop.
Video for demo:
Conclusion
In this, we have learned about docker and how to create docker images from the docker file, and how to run GUI applications inside the docker containers.
Software Engineer | testing, Automation, platform Cloud Engineering. DevSecOps SRE
3 年This is a great post. thanks. How would yo go about having the same setup but displaying firefox in Spanish?