GUI container & application on Docker

GUI container & application on Docker

Step 1 : Configuration and Installation of Docker

In this case I have done the configuration of docker repo and its installation as well with RHEL 8 as the Docker host, to know more about how to do it refer the below link : https://www.garudax.id/pulse/training-ml-model-docker-container-aashish-vivek-bhat

Step 2 : Creating a Dockerfile

Dockerfile is a text file which consists of environmental variables, network port, and other components to write various to build the docker image.

This method is very efficient in comparison to the image building through Docker Commit command with respect to industry use-cases where thousands of containers run in parallel. So instead of launching one container & run our program manually (in case of docker commit command ) we can put all the information inside docker image and once upon launching the container our program will also start & till the time our program is running container will run & once program close, the container so it will stop automatically which is the concept of Dockerfile.

To apply this concept we first create a workspace like "lw_2" in this case in which we will create a file using vim command and it will be names as "Dockerfile".

# vim Dockerfile             // write the name of the file same as given here

After that type the statements/ instructions in the Dockerfile as provided in the snippet to tell the requirements like what image to use and run programs over and what command to run for respective software/package installation like firefox in this scenario, and can refer the latter image showing the statements written in dockerfile.

# FROM centos:latest          // uses the given img on which we'll run our program

# RUN yum install firefox -y  // runs the given command to install req. software

# CMD ["/usr/bin/firefox"]    // runs the firefox cmd as soon as container launch
No alt text provided for this image

Step 3 : Building Docker Image through Dockerfile

After configuring the dockerfile build the docker image based on it using command any of the following commands :

# docker build -t <name> .       
                                
# sudo docker build -t <name> .

Here "-t" refers to the name/tag that we provide to the image which we would be building like "gui_app" in this case and we give period(.) at the end of the command which signifies the Dockerfile, hence no need to mention the dockerfile name in the command above since it itself looks for the file and starts building image from it as shown in the below picture.

No alt text provided for this image

Step 4 : Running GUI application (Firefox) in Docker container

Now Docker doesn't come with a GUI screen to run the Firefox like applications so for that we need to share the docker-host's X-server with the container by creating a volume using command

# --volume="$HOME/.Xauthority:/root/.Xauthority:rw”

Also we need an environment variable for the GUI application to run and network host to share the docker-host by connecting to its main network card using below commands

# --env="DISPLAY"

# --net="host"

Now we will combine above three commands to run the firefox application using the "gui_app" image using the command below and the latter attachment can also be referred.

# docker run --env = "DISPLAY" --net="host" --volume = "$HOME/.Xauthority:/root/.Xauthority:rw”
No alt text provided for this image

After running the above command we can see the Firefox application launched in GUI mode in the below snapshot.

No alt text provided for this image

Now after closing the application we can check out if the container is running or not by using command <docker ps -a> which will show that the container has been stopped by itself after successfully running the program, as we can see the highlighted area in the below image.

No alt text provided for this image


THANK YOU !!!




To view or add a comment, sign in

More articles by AASHISH VIVEK BHAT

Others also viewed

Explore content categories