How to run a GUI container on the Docker?

Ishita Mittal
4 min readJun 1, 2021

--

What is docker?

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.

But, when we launch the docker container, it is automatically redirected to the CLI.

So, here in this article, we will dicuss how we can launch a container in the GUI mode and then we can run any GUI software like Jupyter Notebook on the container.

So, first of all, as a prerequisite, we need to install docker on top of our host machine.

Step-by-Step Walkthrough:

  1. Install docker on the OS:

Here we are using RHEL8, but if you want you can also use windows, mac or any other OS.

First step would be to configure the package installer according to the os and then just install the docker.

So since we are using RHEL8, First of all, we need to configure the yum repository.

=> Open the repositry file in the /etc/yum.repos.d .

=> Write the code shown below in the repository.

=> Now use the below command to install docker.

2. Start and enable the docker services.

Now we need to start and enable (so that docker services automatically starts after booting) the services of docker.

=> Use “systemctl start docker” to start the docker services.

=> Use ““systemctl status docker” to check whether the docker services started or not.

=> Use “systemctl enable docker” to keep the docker services running even after booting the OS.

4. Download the image of centos using the docker pull command.

5. Launch the docker container using the below command:

=> The DISPLAY variable will help us to run the docker container in GUI mode:

6. Install the firefox in the centos using the following command:

=> To run Jupyter Notebook, we need a browser. That’s why we are installing firefox.

7. Now install the python in centos using:

8. Now, install the Jupyter notebook using:

=> We know that pip3 is used to install python libraries in RHEL8 AND jupyter is one of the library of python so we used this command to install the jupyter.

9. Now to run Jupyter notebook in centos container, use the command:

=>- -allow root is used along with the Jupyter Notebook command because of some power concept in linux.

=> Output:

So, our Jupyter Notebook is successfully running on the firefox Browser inside the container.

So, this is how we can run a GUI container on the Docker.

Thank you for reading this article!

Keep learning, keep sharing!!

--

--

No responses yet