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.

--

--

--

2x Red Hat Certified Engineer | Aspiring MLOps & DevOps Engineer | Terraform | Ansible | Jenkins | AWS • GCP • Azure | OpenShift | Kubernetes | Docker | BigData

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Make a Compound Interest Calculator in Microsoft Excel

Is Coding Easy to Learn?

Software Architecture: Therac-25 the killer radiation machine

Gruntwork Newsletter, October 2018

The Interview Process: What to Expect When You Apply to YLD

Hardhat — ethereum development evolution? So, let’s figure it out.

How Not To Make Spaghetti Out Of Python

difference in behavior for copying contents in primitive and non primitive type?

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
Rahulkumar Choudhary

Rahulkumar Choudhary

2x Red Hat Certified Engineer | Aspiring MLOps & DevOps Engineer | Terraform | Ansible | Jenkins | AWS • GCP • Azure | OpenShift | Kubernetes | Docker | BigData

More from Medium

MODBUS PROTOCOL

K8s Challenge from DigitalOcean

Automate Kubernetes Cluster Using Ansible

Access Fargate Windows Container