Running GUI application inside from docker container

Abhinav Shreyash
2 min readJun 1, 2021

--

If you want to run a gui application from inside the docker container then you have forward the x11 socket of the docker container to the local pc , so that gui application run inside the container but the gui svrren appear before your eyes on your local computer , so this is the processes,

Step 1: we need to build the custom image to deploy gui applications , for that we are going to use centos

FROM centos
RUN yum install python3
RUN pip install scikit-learn
RUN pip install pandas
RUN yum install firefox
RUN yum install xauth
RUN pip install matplotlib
COPY ml.py /home/
COPY SalaryData.csv /home/EXPOSE 8887

EXPOSE 8887
CMD firefox

xauth allows the docker container to access the display server.

Step 2: Copying the Cookie to connect X Server Displays

xauth list

command gives the cookie value in the local computer

<username>/unix:  MIT-MAGIC-COOKIE-1  <cookie_value>

Step -3

We Make the docker container using the given command

Docker build -t image:v1 .

Step -4

We run the container —

docker run -it --net=host -e DISPLAY -v /tmp/.X11-unix image:v1 bash

Step 5: Add the cookie to the list

You need to add the cookie copied in the previous step using the following command.

xauth add <cookie>
xauth list

Step 6:Run the Firefox Instance from the bash

To run a Firefox instance, simply type “firefox” inside the bash. You will find that the Firefox browser pops up on your local machine even though it is running inside the Docker Container.

That’s it for now ,

Thanks for reading.

--

--