GUI Container on the Docker..!!

Docker is a software platform for building applications based on containers.There is also a huge scope of Docker Containers impacting the Desktop and Development Environment.Docker, an open source project launched in 2013, helped popularize the technology, and has helped drive the trend towards containerization.

There can be two types of applications (usually services) that you can containerise,

  • Applications that run as a Background Service (like a Database, WebServer, etc)

The second option is what we will see now,

For Running GUI application in a Docker..!!

#In our Project , we are using firefox as our GUI application.

1. Creating the Dockerfile.

  • A Dockerfile is a text configuration file written using a special syntax

create a Dockerfile with the following code:

creating the Dockerfile.
The Code Inside the Docker file.

The above Dockerfile contains the sequence of instructions to create an Centos image, runs an yum install Firefox.

FROM — Select the base image to build the new image on top of.

example : FROM centos:latest

RUN — Specify commands to make changes to your Image and subsequently the Containers started from this Image. This includes updating packages, installing software, adding users, creating an initial database, setting up certificates, etc. These are the commands you would run at the command line to install and configure your application. This is one of the most important dockerfile directives.

example: RUN yum install firefox

CMD — This is the command that will run when the Container starts.

example : CMD [“ /usr/bin/firefox”]

In our Project these CMD [“ /usr/bin/firefox”] is used to save the file.

2. Build the Docker Image

  • The docker build command processes this file generating a Docker Image in your Local Image Cache, which you can then start-up using the #docker run command, or push to a permanent Image Repository.

Create the Docker Image using the following command.

#step 2 : docker build ./

(./ =It will check the Dockerfile in the root directory).

It will Perform all the 3 Commands, which we have written in Dockerfile.

Command 1 & 2
Successfully build the docker image.

Successfully Build the Docker image.

3. Check whether the image is launched.

#docker images

4.Run the Docker Image.

#docker run — net=host — env=”DISPLAY” — volume=”$HOME/.Xauthority:/root/.Xauthority:rw” Imageid.

For a GUI Application to run, we need to have a XServer which is available as part of every Linux Desktop Environment, But within a Container we don’t have any XServer

Therefore, we can :

  • run container with host network driver with

So after executing this , we will get our GUI application (firefox).

firefox successfully launched.

Hence, we can run any GUI App with this same approach.

Hope , you find it Intresting..!!

💫Keep Learning, Keep Sharing💫

--

--

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