Docker

Docker is one of the most common container technology. Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Docker makes application deployment very fast and efficient.

There can be two types of applications that we can containerize.

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

Docker’s normally used to containerize background applications and CLI programs this is the normal trend in the market. But we can also use it to run graphical programs, YES we can!!!

First of all we have to aware how a GUI program Run on machine with the help of OS. So there is a X server program which helps a GUI program to run on a system window.

An X server is a program in the X Window System that runs on local machines i.e. the computers used directly by users and handles all access to the graphics cards, display screens and input devices (typically a keyboard and mouse) on those computers.

But We know that Docker container run in a isolated environment and don’t have any X server program. So what we can do,

  • share the Host’s X Server with the Container by mounting a volume. It can be found /tmp/.X11-unix on linux host.
  • share the Host’s DISPLAY environment variable to the Container. This instructs X client our graphical programs. which X server to connect to.
  • run container with host network driver.

So Lets start….

For Doing this practical my plan is like:-

  • Firstly create a docker image, in this a GUI program install ( I choose Firefox) with the help of Dockerfile.
  • Then create a Docker-compose file to deploy our container.(By simple command we also deploy our GUI container)

Docker Image

FROM centos
RUN yum install firefox -y
CMD ["/usr/bin/firefox"]

Dokcer-compose file

version: "3"services:
app:
image: mukuljeveriya/firefox_container:v1
build: .
environment:
- DISPLAY=${DISPLAY}
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
network_mode: host
Dockerfile and Docker-compose file
All the images available in my host machine

we can firstly build the image or direct run the docker-compose file via command.

docker-compose up

By this command firstly docker image build named as mukuljeveriya/firefox_container:v1 and then all the services write in docker-compose file will start.

Look in the above image service start successfully. Our GUI application run inside a docker container.

RESULT:

On my host machine RHEL8 installed but here you can see as I took centos as a base image in my dockerfile so the Firefox run on Centos.

You can see mukuljeveriya/firefox_container:v1 image, this is the image I created in which I installed Firefox.

We can also launch our GUI container directly with docker command without docker-compose.

docker run --net=host --env="DISPLAY" -v /tmp/.X11-unix:/tmp/.X11-unix --name <any name> <imagename/:version>

Thanks for reading , I hope you like the Blog!!!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What is an IoT SIM card?

30 plus SSH interview questions and answers — compiled

Migrate Amazon RDS (MySQL) Data from Azure MySQL — MyDumper, MyLoader

K8s deployments using Spinnaker

When The PHP DateTime Object is Too Precise

Extracting more values from application logs

Acer Spin 1 (SP111–32N) and Chromium OS

Optimizing Reliability: Step 2 — Calculate Sensor Failure Points

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mukul Jeveriya

Mukul Jeveriya

More from Medium

Advantages of Using Docker for Microservices

[Ubuntu 20.04][MySQL5.7]Problems installing mysql5.7 on Ubuntu 20.04

Tutorial: execute code in a remote machine using the ClearML queue

Install MySQL 8.0 on ubuntu Server