Running GUI Application on Docker Container

Monil Goyal
3 min readJun 1, 2021

--

How to run applications that require a graphic user interface on the docker container.

Have you ever tried to run a GUI application on the docker container?

if no, then let me show you how can we do this.

As we know docker container comes with a command-line interface in which we can not run GUI applications by default. So we have to provide it with a display and the host’s network driver.

Launching GUI Container

Note: To launch docker container with GUI Base OS must have GUI facility.

  • To launch a docker container we use the docker run command
docker run -i -t --name <container_name> <image_name>

→ -i enable the container to interact

→ -t provide the terminal.

  • To launch a container with GUI, we have to provide DISPLAY environmental variable to the container.
--env=”DISPLAY”

→ The container will basically use the Display adaptor of the Base OS to take the parameters of the mouse pointer, cursor, etc.

  • To set network adopter as host pass the following option to the docker run command.
--net=host

I am going to use centos image with the latest version.

So over final command is:

docker run -it --name gui_docker --env="DISPLAY" --net=host centos:latest

Our container has been successfully launched, Now we can run GUI application in it.

Launching GUI application on Docker

I am going to install a python IDE i.e. jupyter notebook that requires GUI to run.

To install jupyter notebook we have to install python in our container.

After successful installation of python, we will install jupyter notebook by pip package manager of python.

Now, this command will fail because jupyter notebook requires any browser to run.

So, we will install firefox to run the notebook.

Now, let's run jupyter notebook.

To bypass root power, it is asking to run with the following option

--allow-root

Now, our GUI application has been successfully launched.

Thanks, for reading…

Keep Learning Keep Sharing !!!

--

--