How to run GUI Application inside Docker Container

Aman Rathi
2 min readMar 11, 2021


Docker containers run as a process under the main operating system, you can run multiple containers on a single machine. This means that, instead of choosing the exact right size for each machine, you can simply provide a large machine and run several Docker containers on that machine. If you need more horsepower for one of your containers, you can simply move it to a new machine. Mostly container applications run in background mode but we can run foreground (GUI application) over docker container if the base os have GUI facilities.

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, for this you have to,

1.share the Host’s Display environment with container


2. set the networking to the host driver


— net=host option is used to make the programs inside the Docker container look like they are running on the host itself

3. share your Host’s Xserver with the container by mounting it with container volume



Baseos must be GUI enabled


Let us launch a container by centos image on base os (Red Hat GUI enabled) using the above rules

Then install a GUI application like gedit by yum command or any other application your need, lets open a file with gedit command

Here you can see that gedit is running in GUI mode with some warnings in the backend.

Thank You