GUI container on the Docker

Divesh Karkera
4 min readMay 31, 2021

In this blog, I am gonna show you how to launch a container on docker in GUI mode. We are going to run GUI software on the container.

What if you need to run a firefox program inside a Docker compartment?. Yes, we can do that but first, we should examine the kind of application and how it runs. There are significantly two kinds of applications that can be containerized.

  1. Applications that run as a Background administration eg: webserver
  2. GUI Application that runs in the closer view i.e Foreground.

Along these lines, for any GUI application to run, we need to have XServer which is now accessible in all Linux frameworks.

Why Xserver?

Let's Understand why Xserver is important An X server is a program in the X Window System that runs on local machines (i.e., the computers used directly by users) and handles all access to the graphics cards, display screens and input devices (typically a keyboard and mouse) on those computers.

However, when we Launch a Container, we don’t have Xserver configured here, so we need to configure it first.

  1. We create a Volume and share the Host’s XServer with the container

Command: — volume= “$HOME/ .Xauthority: /root/.Xauthority:rw”

here we are sharing our docker host i.e. RHEL8 XServer.

Now we have to share the host display environment with the container. also, we have to run the container with the host network. So we have to run the container by these options.

Here we have given the file name js

Now we have to install few things such as basic software like ncurses, net-tools to check IP Address. We also need to install Python inside the docker container. Also to run Jupyter Notebook we need a browser so we are going to install Firefox and Jupyter Notebook.

Here I have installed the above 3 things priorly in my docker but I will provide you with the commands to install the above tools.

  1. Command to install net-tools:- yum install net-tools -y
  2. Command to install python:- yum install python3
  3. Command to install firefox:- yum install firefox -y
  4. Command to install Jupyter:- pip3 install jupyter

After The installation of the mentioned things above it's time to create a working area for our jupyter notebook to train the model.

Now, let's transfer our dataset from RHEL8 i.e docker host to our container.

Run the command below :

docker cp <SOURCELOCATION> <CONTAINERNAME>:<DESTINATIONLOCATION>

as soon as your dataset is transferred We need pandas, NumPy,sci-kit-learn etc. let's install them using pip3 But before that will use the pip3 list command. It returns the list of packages in the current environment. It also returns the installed version for each package.

Command:- pip3 list

Now to install pandas, NumPy,sci-kit-learn etc the command is given below:

pip3 install pandas numpy scikit-learn

Now our environment is ready inside the docker.

Now, run the Command: jupyter notebook — allow-root

As soon as the command runs the Jupyter notebook will be visible and you can create a new python3 notebook.

We have successfully Launched a container on docker in GUI mode. you can do all the process here.

Thanks for reading!

--

--