Running GUI Apps inside Docker Container

Architecture of this task

IT industry is focusing on Time saving and creating such technologies that can work smartly and fast. One of such technology is Docker that is a containerization tool.

There are two types of Applications or services can be used inside a Docker Container, that are:

  1. Applications that run as a Background Services(like webserver).
  2. GUI Applications that runs in Foreground

For a GUI Application to run, we need to have a XServer which is available as part of every Linux Desktop Environment, But within a Container we don’t have any XServer, so we will

  • Share the Host’s Xserver to the container OS by creating a volume,
  • --volume="$HOME/.Xauthority:/root/.Xauthority:rw"
  • Share the DISPLAY environment variable to the Container OS
  • --env="DISPLAY"
  • run the OS with Host’s Network driver
  • --net=host


Step 1: Pull a docker image named centos:latest

Note: I am using centos, here we can use our customized docker images also.

  • docker pull centos:latest
No image name centos:latest
pulling centos:latest docker image
Successfully installed Docker image

Step 2: Creating a docker container with all the properties that are listed above ( Xserver, DISPLAY environment variables and Network driver).

sudo docker run -it --name uibasedos --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" centos:latest
Successfully created and entered into the docker container

Step 3: Installing any GUI App

Suppose we will launch firefox here, using command “yum install firefox -y”

installing firefox
Successfully installed firefox

Step 4: Using this Firefox App

Opening Firefox
Successfully opened Firefox

Step 5: Exiting the Container OS, using “exit” command

Exited the container OS
List of all the docker containers

Hence, we can run any GUI App with this same approach.

💫Keep Learning, Keep Sharing💫



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anshika Sharma

Anshika Sharma

I am a tech enthusiast, researcher and work for integrations. I love to explore and learn about the new technologies and their right concepts from its core.