Run GUI Application inside Docker Container

Hello everyone,

In this blog we are going to launch GUI[Graphical User Interface] application inside docker container.

Before we start with main topic let’s first discuss what containerization is and what is Docker?

Containerization

Con…


This content originally appeared on DEV Community and was authored by Nitesh Thapliyal

Hello everyone,

In this blog we are going to launch GUI[Graphical User Interface] application inside docker container.

Before we start with main topic let's first discuss what containerization is and what is Docker?

Containerization

Alt Text

Containerization is a technology that created a virtual OS environment where we can work like we usually do in our system. It launches the new OS , Install the OS and boot the OS in seconds and it saves lots of time and solve many use case.

The tool or software that works on Containerization is Docker.

Alt Text

Prerequisite:

  • Linux OS
  • Docker installed

  • First start docker container

To start docker container use command systemctl start docker

  • Start container

To start container first we need to download image, to download image use command docker pull centos:7

now use command docker run -it centos:7 to launch docker container.
here centos:7 is image name with its version.

Alt Text

  • Install GUI application

here I am installing Firefox to check if it is running or not in docker container.

To install Firefox use command yum install firefox

Alt Text

Now launch Firefox using command firefox

Alt Text
here we can see it is asking for display as in containers no display environment variable are not present.

To solve this issue we need to launch new container with X Server.

What is X Server?

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. Services can communicate with the X server to display graphical interfaces and receive input from the user.For detail

Alt Text

Now launch the docker container using command
docker run -it --name dockergui --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" nitesh007/ml

Alt Text

Let's understand this command:

  • run :- this keyword will launch the container
  • -it :- this gives interactive terminal
  • --name :- use to set the name the name of container
  • dockergui :- it is name name of container, you can give any name
  • --net=host :- use to launch the container with host network
  • --env="Display" :- This is use to share the display of the host to the container
  • --volume="$HOME/.Xauthority:/root/.Xauthority:rw" :- This is use to share the host X server with the container by creating volume.
  • nitesh007/ml :- this is my docker image name that has all required packages used in machine learning.

After launching the container install the following software/packages.

  • Python3
    command: yum install python3

  • Scikit-learn
    command pip3 install scikit-learn( To run Machine learning model )

  • Jupyter Notebook
    command: pip3 install jupyter ( It is ide in which we will run ML model )

  • Firefox
    command: yum install firefox (To run Jupyter Notebook, browser is required )

Now we have installed required packages, it's time to run our model.
But for that we require dataset!

To copy dataset from base OS to container use command
`docker cp :

Now we have everything that is required.

  • Run Jupyter Notebook to run ML code

To launch Jupyter Notebook use command in the directory that has code jupyter notebook --allow-root

Alt Text
earlier it didn't launched as it is GUI application and container does not have display so it did not work earlier but now we can see it is working fine and we can work on it.

Alt Text

Alt Text

To watch the demo click on the video mentioned below⭐

Thank you!!


This content originally appeared on DEV Community and was authored by Nitesh Thapliyal


Print Share Comment Cite Upload Translate Updates
APA

Nitesh Thapliyal | Sciencx (2021-05-30T18:16:31+00:00) Run GUI Application inside Docker Container. Retrieved from https://www.scien.cx/2021/05/30/run-gui-application-inside-docker-container/

MLA
" » Run GUI Application inside Docker Container." Nitesh Thapliyal | Sciencx - Sunday May 30, 2021, https://www.scien.cx/2021/05/30/run-gui-application-inside-docker-container/
HARVARD
Nitesh Thapliyal | Sciencx Sunday May 30, 2021 » Run GUI Application inside Docker Container., viewed ,<https://www.scien.cx/2021/05/30/run-gui-application-inside-docker-container/>
VANCOUVER
Nitesh Thapliyal | Sciencx - » Run GUI Application inside Docker Container. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/30/run-gui-application-inside-docker-container/
CHICAGO
" » Run GUI Application inside Docker Container." Nitesh Thapliyal | Sciencx - Accessed . https://www.scien.cx/2021/05/30/run-gui-application-inside-docker-container/
IEEE
" » Run GUI Application inside Docker Container." Nitesh Thapliyal | Sciencx [Online]. Available: https://www.scien.cx/2021/05/30/run-gui-application-inside-docker-container/. [Accessed: ]
rf:citation
» Run GUI Application inside Docker Container | Nitesh Thapliyal | Sciencx | https://www.scien.cx/2021/05/30/run-gui-application-inside-docker-container/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.