GUI Application over Docker Container

Launching GUI software on Docker Container using Manual and Dockerfile process.

--volume="$HOME/.Xauthority:/root/.Xauthority:rw"
--env="DISPLAY"
--net=host

Note: Here, In this article we will look both ways i.e Manually in the container and Dockerfile.

Github URL for all Dockerfile codes: https://github.com/Rahulkumar0909/Dockerfiles

Note: I have used RHEL8 operating system. You can use Centos or Fedora also.

Step1: Deploy Container

docker run -it --name os1 \
> --net=host \
> --env="DISPLAY" \
> --volume="$HOME/.Xauthority:/root/.Xauthority:rw" centos:latest

Step2: jupyter notebook needs browser to execute so, we will install dependencies

yum install firefox python3 -y

Step3: Let’s install jupyter now

pip3 install jupyter

Step4: Checking the installation

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

Step5: Finally launch jupyter notebook

jupyter notebook --allow-root

Note: Running as root is not recommended. Use — allow-root to bypass.

Step1: Deploy Container

docker run -it --name os1 \
> --net=host \
> --env="DISPLAY" \
> --volume="$HOME/.Xauthority:/root/.Xauthority:rw" centos:latest

Step2: Installing software

yum install gedit vim -y

Step3: Run gedit

/usr/bin/gedit
Build process

Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

Step1: Dockerfile code

FROM centos:latest
RUN yum install firefox python3 -y
RUN pip3 install jupyter
ENTRYPOINT ["/bin/bash"]

Step2: Build

docker build -t <name_of _image>:<tag> .Example:
docker build -t jupyter-notebook-image:v1

Step3: Deploy Container

docker run -it --name os1 \
> --net=host \
> --env="DISPLAY" \
> --volume="$HOME/.Xauthority:/root/.Xauthority:rw" \
> jupyter-notebook-image:v1

Step4: Run command

jupyter notebook --allow-root

I have created a docker image named as rahul079/jupyter-notebook-gedit, which you can just pull and run the code!

Step1: Pull the image from docker hub

docker pull rahul079/jupyter-notebook-gedit:v1

Step2: Deploy Container

docker run -it --name os2 \
> --net=host \
> --env="DISPLAY" \
> --volume="$HOME/.Xauthority:/root/.Xauthority:rw"
> rahul079/jupyter-notebook-gedit:v1

Step3: Just run the command and start coding!

jupyter notebook --allow-root

or for gedit,

/usr/bin/gedit

Thank You for Reading!

connect me :

Developer | ARTH Learner @LinuxWorld | IIEC RISE Student | ML • DL • DevOps [MLOps] Enthusiast | AWS • GCP • Azure ☁️