GUI Application over Docker Container

For a GUI application to run, we need to have an Xserver which is available as part of every Linux Desktop Environment, But within a container, we don’t have any Xserver so,

🔰 Share the Host’s ‘Xserver’ with the container by creating a volume

--volume="$HOME/.Xauthority:/root/.Xauthority:rw"

🔰 Share the host’s ‘DISPLAY’ environment variable to the container

--env="DISPLAY"

🔰Run container with host network drive with

--net=host

So, First let us look manual process

Steps to run jupyter notebook in container:

docker run -it --name os1 \
> --net=host \
> --env="DISPLAY" \
> --volume="$HOME/.Xauthority:/root/.Xauthority:rw" centos:latest
yum install firefox python3 -y
pip3 install jupyter
jupyter --versionjupyter core     : 4.7.1
jupyter-notebook : 6.4.0
qtconsole : 5.1.0
ipython : 7.16.1
ipykernel : 5.5.5
jupyter client : 6.2.0
nbconvert : 6.0.7
ipywidgets : 7.6.3
nbformat : 5.1.3
traitlets : 4.3.3
jupyter notebook --allow-root

Steps to run gedit on container:

docker run -it --name os1 \
> --net=host \
> --env="DISPLAY" \
> --volume="$HOME/.Xauthority:/root/.Xauthority:rw" centos:latest
yum install gedit vim -y
/usr/bin/gedit

Now, let’s look the Dockerfile process

Build process
FROM centos:latest
RUN yum install firefox python3 -y
RUN pip3 install jupyter
ENTRYPOINT ["/bin/bash"]
docker build -t <name_of _image>:<tag> .Example:
docker build -t jupyter-notebook-image:v1
docker run -it --name os1 \
> --net=host \
> --env="DISPLAY" \
> --volume="$HOME/.Xauthority:/root/.Xauthority:rw" \
> jupyter-notebook-image:v1
jupyter notebook --allow-root
docker pull rahul079/jupyter-notebook-gedit:v1
docker run -it --name os2 \
> --net=host \
> --env="DISPLAY" \
> --volume="$HOME/.Xauthority:/root/.Xauthority:rw"
> rahul079/jupyter-notebook-gedit:v1
jupyter notebook --allow-root
/usr/bin/gedit

Done! That simple.

--

--

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