parthanaboina praveen
2 min readMay 31, 2021

--

Running GUI Application inside Docker Container :

Customized Docker Image Building :
Let’s say we want to run “firefox” program inside Docker Container. So, what we can do is — We can create one Docker Image & can say whenever any container launch from this Image, run the Firefox program. So, let’s create the “Dockerfile”…

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

As we can notice it’s a short basic “Dockerfile” which is using “centos:8” image & installing “firefox” software in it. Then finally it’s starting the Firefox software using “CMD” keyword.
Now let’s build the image…
# docker build -t myfirefox:v1 .
Once build is done, let’s launch the container. So as like previous time run the below mentioned code…
#docker run -it --name firefoxos1 myfirefox:v1

You will see errors & finally Firefox will not launch successfully. Why ?
Logic is Firefox need one environmental variable to run itself. This shell variable actually help Firefox to project it’s gui tab on screen. Now we definitely know that Docker Container don’t has a gui screen to run the Firefox, that’s why we need to tell the container to use the host system’s gui screen & for that we gonna use that environmental variable using the option “env” in “docker run” command. So, run the below mentioned command

#docker run -it --name firefoxos2 --env="DISPLAY" --net=host myfirefox:v1
Now it’s obvious that you might be thinking why we need “net” option, in this command. Here, this is a networking concept, but in basic if we want to understand, then you can think this option goanna connect your docker container with your RHEL8 docker host’s main network card. This option is actually needed because after launching container it will provide us the Firefox software in GUI window, now whatever we are searching in this window needs to go to the Docker Container via Docker Host. For that connectivity we add our Docker Host network to the container.
That’s all… Now let’s see it in action in the below GIF…

Thanks for reaching.

--

--