How to run GUI Software in Docker

Ansh Kumar Dev
3 min readJun 1, 2021

As is we all know docker provides us a CLI interface where we can only run commands and cant use a graphical interface. So here the question arises of how we can run GUI software inside Docker. This is very easy, we need to make some changes in ‘xhost’ so that the docker container can use DISPLAY of the host.

So, first of all, we will be finding the number of our display so that we can make our CLI understand that on which DISPLAY it can run itself. For this we are going to use this command: echo $DISPLAY

Now we have to export our display so that it can be accessed by any program. For this, we are going to use this command: xhost +

Now we need to create a docker file. Here we have to define certain things which are as follows:

  1. we are using centos image so we have to mention it
  2. Updating our yum repo
  3. Installing python3, firefox, and jupyter
  4. and what we have to run which is firefox

Now we will be building our docker file using this command:

docker build -t gui:v1 .

Here gui is our image name (we can give any ), v1 is the version ( we can give any) and we have used ‘ . ’ to tell that we are running this command in place where we have Dockerfile .

Now we will be launching our container using command:

docker run -ti— — net=host — env=“DISPLAY” gui:v1

Here is the final result. We have successfully opened a GUI software inside Docker.