Run GUI Programs on Docker Container

Run GUI Programs on Docker Container

Task Description -

Run a Docker container that can run GUI (Graphical User Interface) Programs

  1. Launch a container on docker in GUI mode.
  2. Run any GUI software on the container

Prerequisite

  1. Docker Installed on your system.
  2. Docker Host should be GUI-based.

Note: I’m Using RedHat Enterprise Linux V8 in this practical.

What is Docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production. (source: docs.docker.com)

Docker provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allow you to run many containers simultaneously on a given host. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host. You can easily share containers while you work, and be sure that everyone you share with gets the same container that works in the same way.

Developing with Docker

Developing apps today requires so much more than writing code. Multiple languages, frameworks, architectures, and discontinuous interfaces between tools for each lifecycle stage create enormous complexity. Docker simplifies and accelerates your workflow while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project.

Problem

Sometimes we need to run GUI programs in containers to debug or test the things but most of the people stuck there that How to run GUI programs in a docker container.

So, Lets get Started

It is very easy to run GUI programs in a docker container.

So, first, we have to Launch a Container from some base image, here I’m using the official centos Linux docker image. And while launching container give environment variable $DISPLAY to container and in Volume of container mount the path of x11 server/display. Give a name to your container and launch it.


docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ --name GUIcontainer centos        

That’s all we need to do, Now we can Run any GUI program in this container.

No alt text provided for this image

So, in this practical I’m gonna Run —

  1. Firefox (Web browser)
  2. Jupyter notebook (python IDE)
  3. Gedit (Text editor)

Run Firefox Web Browser

Firefox is a Graphical user interface program. For this program we need a graphical display to Run.

So, first we have to install Firefox’ browser in our launched container.

yum install firefox -y        
No alt text provided for this image

Install Firefox browser

Now, Run firefox’ command to launch browser.

firefox        
No alt text provided for this image
Run Jupyter Notebook

For launching ‘Jupyter notebook’ we need ‘python3’ interpreter/package to be installed in container. so, first install python package by running below command.

yum install python3 -y        
No alt text provided for this image

Now, through ‘pip3’ command install ‘jupyterlab’ for jupyter notebook.

pip3 install jupyterlab        
No alt text provided for this image

Install ‘jupyterlab’

Now after installing ‘jupyterlab’ Run ‘jupyter notebook’.

Here see carefully, we have to run ‘jupyter notebook’ with root privilege, by adding ‘--allow-root’ option in ‘jupyter notebook’ command.

jupyter notebook --allow-root        
No alt text provided for this image

Here, we can see jupyter notebook is launched successfully. we can write our python code here and Run it very easily.

Jupyter notebook is a web app, this is why it launched in ‘Firefox’ browser, that’s why we need to install Firefox browser before running jupyter notebook.

No alt text provided for this image
Launch Gedit (Text Editor)

Now install ‘gedit’ package in container. It is a GUI based Text editor.

yum install gedit -y        
No alt text provided for this image

After Installing gedit, run it, and write anything whatever you want to write.

Using gedit text editor is very easy.

####  gedit <text_file_name>  ####gedit docker        
No alt text provided for this image

Write anything you want to write in this file and save it.

Here I have written a very simple python code.

No alt text provided for this image

If you have written some code then you can execute/run it.

Or if you have written something else then you can see that by using ‘cat’ command or by again opening gedit.

No alt text provided for this image

My python code is executed successfully.


That’s All.

THANK YOU For Reading!!!

Abhi M.

Looking for Opportunities in Cloud

2 年

Hey Udit i want to know about ARTH Program can you connect with me

回复

要查看或添加评论,请登录

Udit Agarwal的更多文章

社区洞察

其他会员也浏览了