LAUNCHING GUI-ENABLED DOCKER CONTAINER AND RUNNING FIREFOX INSIDE IT
Summer@LinuxWorld — Task 02 👨🏻💻
Task Description 📄
🔰 GUI container on the Docker
🔰 Launch a container on docker in GUI mode
🔰 Run any GUI software on the container
Before getting into the task, lets discuss something about docker.
Docker is the de facto standard to build and share containerized apps — from desktop, to the cloud. Ever since its launch in 2013, companies are adopting docker at a remarkable rate.
REASONS TO USE DOCKER
- Docker enables developers to easily pack, ship, and run any application as a lightweight, portable, self-sufficient container, which can run virtually anywhere.
- Containers, however, use shared operating systems. This means they are much more efficient than hypervisors in system resource terms. Researchers say that with a perfectly tuned container system, you can have as many as four-to-six times the number of server application instances as you can using Xen or KVM VMs on the same hardware.
- Docker helps in Continuous Integration/Continuous Deployment (CI/CD).
- Docker containers are easy to deploy in a cloud.
- With the help of docker,we can break big development projects among multiple smaller units and teams can work on it independently.
Docker does not suit applications that require a rich UI. Docker is mainly intended for isolated containers with console-based applications. GUI-based applications are not a priority, their support will rely on the specific case and application.
Lets see what happens when we try to launch firefox ( which requires Web UI ) inside a docker container.
docker run -it --name test centos:latest
The above command launches a docker container with an interactive terminal from centos image.
The error clearly says that no display environment variable was specified. This is the reason why firefox didn’t launch.
To enable GUI, we need to share our host X11 socket with the container ( mount /tmp/.X11-unix folder to the container ) and Run docker container with environment variable DISPLAY.
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.
To launch GUI enabled docker container run the following command:
docker run -i -t -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --name=test1ing centos:latestwhere, -i stands for interactive
-t stands for terminal
-e stands for Export Environment variables
-v stands for Bind mount a Volume
--name to give container name
After launching the container, install firefox using yum command and try to launch it.
Running a GUI program in Docker can be a useful technique when you’re evaluating a new piece of software. You can install the software in a clean container, instead of having to pollute your host with new packages.
This approach also helps you avoid any incompatibilities with other packages in your environment. If you need to temporarily run two versions of a program, you can use Docker to avoid having to remove and reinstall the software on your host.
So that’s it from my side. I successfully completed task 2 of my summer program.
Thank you readers for taking the time to read my story.