Launching GUI Applications Inside Docker Container.

Nityachawda
3 min readJun 1, 2021

Hello Readers,

In this article, we will be looking into how we can launch GUI applications inside the Docker container.

There are some prerequisite to do the following task:

Docker provides two versions of Docker

  • Docker community version.
  • Docker enterprise version.

Docker should be installed. To install the docker first we have to configure the yum repo. After configuring yum we can install the docker community version.

Just create an file inside the /etc/yum.repos.d/ with .repo as extension and write the content from the below image.

Command to install docker.

yum install docker-ce --nobest

After installing Docker, we have to start the docker service.

To start the docker service in RHEL v8:

systemctl start docker

Let’s start doing this task:

First, we will be creating our image in which we will install python and jupyter-notebook by using dockerfile.

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

The name of the file should be dockerfile only.

DOCKER FILE:

FROM centos:7
RUN yum install python3 -y
RUN pip3 install jupyter
CMD [“/usr/local/bin/jupyter”]

We are using base os has centos version 7. After launching the container with the base image this file will install python version 3 and jupyter in the container.

After writing this file we will now run the file.

To run the above file:

docker build . -t notebook

(-t) flag is used to give the tag to the image. The tag we are giving is a notebook.

This command will create the Image.

Now, we will launch the container with the launched image.

Command to launch the container:

docker run -it --name OS1 --env=”DISPLAY” --net=host notebook jupyter notebook --alow-root

This command will launch the container with the name OS1 and passed the env variable with DISPLAY in the container to provide GUI to our operating system and net=host means running our container as the same network as the host.

After running this command a container will be launched successfully.

And that’s it our Jupyter notebook is launched we just need to copy the link and paste it into the browser.

Here is our output. We have successfully launched the GUI application inside the docker container.

💫Thanks for reading.💫

--

--