Run a GUI Software inside a Docker Container
Amit Sharma
DevOps Engineer | Proficient in Docker, Kubernetes, Jenkins, Terraform, Git-GitHub | Deep Learning Enthusiast | AWS Cloud Enthusiast | Coding in Python & C++ |
Introduction-
Docker has been a game-changer in modern software development, offering a reliable platform for creating isolated and portable environments known as containers. Until now, Docker was mostly associated with command-line applications and server-side services. However, the limitations with GUI applications in containers have been overcome, unlocking a whole new possibilities for developers and users alike.
Steps:
1. Install and run the firefox inside docker
Check the status of docker
systemctl is-active docker
systemctl enable docker
systemctl status docker
Launch the container
docker run -it --name machinelearning --net=host \
--env="DISPLAY" \
--volume="$HOME/.Xauthority:/root/.Xauthority:rw" \
centos:7
--net=host
This option configures the container to use the host network stack. It means that the container will share the host’s network namespace, and any network services running on the host will be directly accessible from within the container.
--env="DISPLAY"
This option sets the ‘DISPLAY’ environment variable inside the container. The ‘DISPLAY’ environment variable is used by GUI applications (like graphical user interfaces) to determine where to display their windows. By setting this variable, you enable GUI applications running in the container to use your local X11 server for displaying their graphical interface.
--volume="$HOME/.Xauthority:/root/.Xauthority:rw
This option creates a volume mount that links the ‘.Xauthority’ file in your home directory (`$HOME`) on the host machine to the corresponding location in the container’s root directory (‘/root/.Xauthority’). The ‘:rw’ at the end of the mount specifies that the volume is mounted in read-write mode. The ‘.Xauthority’ file contains credentials that allow the container to connect to the X11 server running on the host, enabling X11 forwarding.
Overall what this command is doing is -> running a CentOS 7 Docker container with support for GUI applications. The options and configurations are set up in a way that allows the container to access the host system’s graphical resources (such as X11 server) and network services (by using host network mode).
Check the running containers
docker ps
We?are inside the container.
Install python
yum install python3 -y
Result
Check the version of python
python3 --version
Install firefox
yum install firefox -y
Check if firefox got installed
rpm -q firefox
Run the firefox in the backgroud
firefox &
There an error should come
process 229: D-Bus library appears to be incorrectly set up; failed to read machine uuid: UUID file ‘/etc/machine-id’ should contain a hex string of length 32, not length 0, with no other text
See the manual page for dbus-uuidgen to correct this issue.
D-Bus not built with -rdynamic so unable to print a backtrace
领英推荐
Redirecting call to abort() to mozalloc_abort
They are instructing to generate a unique machine id for the container
Check the file in the host OS
Same kind of id we need in the container too.
To solve it we will use?dbus?software.
[root@localhost /]# rpm -q dbus
dbus-1.10.24-15.el7.x86_64
[root@localhost /]# cat /etc/machine-id
cat: /etc/machine-id: No such file or directory
[root@localhost /]# dbus-uuidgen > /etc/machine-id
[root@localhost /]# cat /etc/machine-id
a38d9f05617e59d4077ed17f64c1fc06
Now run firefox again
Click on the new tab
Firefox is working fine and that is too in the container
You can search anything in it
Now let’s go to the next process.
2. Installing Jupyter-notebook and run inside docker container
pip3 install jupyter
you may face this error
Upgrade pip and setuptools
python3 -m pip install --upgrade pip setuptools
The will ensure, you have the latest versions of ‘pip’ and ‘setuptools’ installed on your Python environment. Upgrading ‘setuptools’ can help in handling package installations and distributions more efficiently.
Result
Install jupyter-notebook
pip3 install jupyter
Run jupyter-notebook
But it is always better to create separate workspace and then run the notebook.
jupyter-notebook --ip=0.0.0.0 --allow-root
--ip=0.0.0.0
This option sets the IP address on which the Jupyter Notebook server will listen for connections. Setting it to ‘0.0.0.0’ means the server will listen on all available network interfaces, allowing connections from any IP address (including the local host and external IP addresses).
--alow-root
By default, Jupyter Notebook does not run with root privileges for security reasons. However, the--allow-root?allows Jupyter Notebook to run as the root user.
I'm confident that this article will prove to be valuable, helping you discover new insights and learn something enriching .
thank you : )
Digital Marketing Associate | Passionate About Digital Transformation & Audience Engagement
1 年Register for our latest webinar on Managing applications with kubernetes.?? Registration Link: https://lnkd.in/ggysxK5g #docker #kubernetes #course #registernow
Engineering Student | MERN Stack and Flutter Developer | DevOps Enthusiast | Python Programmer | President RAIoT Labs
1 年Amazing ??