Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 30, 2021 06:16 pm GMT

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

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!!


Original Link: https://dev.to/niteshthapliyal/run-gui-application-inside-docker-container-3npg

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To