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 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.
- Linux OS
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.
- 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
Now launch Firefox using command
To solve this issue we need to launch new container with 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
Now launch the docker container using command
docker run -it --name dockergui --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" nitesh007/ml
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.
yum install python3
pip3 install scikit-learn( To run Machine learning model )
pip3 install jupyter( It is ide in which we will run ML model )
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
To watch the demo click on the video mentioned below⭐