Running GUI based applications inside docker container

Running GUI based applications inside docker container


No alt text provided for this image


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

No alt text provided for this image

After installing Firefox, if you try to launch firefox using ‘/usr/bin/firefox’ command, it will show the below error:

No alt text provided for this image

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:

No alt text provided for this 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

No alt text provided for this image

And now, it is the time to launch the container:

docker run -it --name <osname> --env "DISPLAY" --net host <imagename>:<version>

No alt text provided for this image

And the GUI application (firefox) has been launched inside the container:

No alt text provided for this image

We have successfully completed the task.


KEEP LEARNING !! KEEP SHARING !!

-Thank you :)


要查看或添加评论,请登录

社区洞察

其他会员也浏览了