How To Launch Gui Application In Docker

Hey, guys hope you all are doing good in today's article we are going to launch a GUI application inside the docker container sounds interesting, isn't it?

First, we will create our docker image with the required software for that use the code provided below here I am installing Mozilla in docker you can install the software according to your need.

FROM centos:8
RUN yum install firefox -y
CMD firefox

To build your Image first create a folder with any name you like inside it make one file name Dockerfile make sure to use exactly the same file name and put the above code in that code we are telling docker to use centos as a base image and install the firefox RUN keyword during build time and CMD keyword run while creating the container after all the step run the below command to build the image.

docker build -t [image name] .

Once the image is created now we have to launch the container from our image for launching the container use the below command.

docker run -it [container name] — — env=”DISPLAY” — — net=”host” [imagename]

In the above command, we are using env= display variable which will use your host system display when you print display variable it will show 0 by default and 0 points to host screen, and net=host is used so that when container I launched it will launch in hos network stack so that we can directly access it if not use this it will use bridge connection.

Guys, here we come to the end of this blog I hope you all like it and found it informative. If have any query feel free to reach me :)

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