Running GUI based applications inside docker container
Nirali Arora
Microsoft certified Data Analyst and Fabric developer | SQL | Power BI | AI / ML | AWS | Linux | Python | MongoDB
Why Run GUI Apps in Docker?
Running a GUI program in Docker can be a useful technique when you’re evaluating a new piece of software. You can install the software in a clean container, instead of having to pollute your host with new packages.
This approach also helps you avoid any incompatibilities with other packages in your environment. If you need to temporarily run two versions of a program, you can use Docker to avoid having to remove and reinstall the software on your host.
Let’s first try to run a GUI application (say, Firefox) inside a docker container.
For this first we will have to launch a container so here I am launching a container with centos image.
As docker container doesn't bydefault comes with firefox so we are installing it with yum cmd.
docker run -it --name <osname> centos
yum install firefox -y
After installing Firefox, if you try to launch firefox using ‘/usr/bin/firefox’ command, it will show the below error:
The error says that a “DISPLAY” environment was not found. So, here are the steps we are going to perform in order to solve the error:
- Create a Docker image that has firefox installed
- Launching container by providing it with a DISPLAY variable. Also, we will launch it in a ‘host’ network. Host network by default exposes a container so that it can be directly used from the base OS.
Dockerfile for creating the docker image:
Creating the docker image:
docker build -t <imagename>:<version> <file location>
docker build -t dockerwidgui:v1 .
here dot (.) represents that Dockerfile is in current folder
And now, it is the time to launch the container:
docker run -it --name <osname> --env "DISPLAY" --net host <imagename>:<version>
And the GUI application (firefox) has been launched inside the container: