Launching GUI on Docker

— Using graphic based application on containers

Container are used for specific use cases only. For example, one container is used for hosting web services, and another to host database services, not using single container for both use cases.
That means, containers are designed to be light, so that they can process fast. As we know graphics requires lots of computing and processing, thus tends to slow the system comparatively. Thus by default graphics are not supported in containers.

But sometimes we may want to use some graphical based tools, software etc. For example, launching a python environment in container. as discussed in previous article:

As a programmer, we are more comfortable in writing code in I.D.Es or some editors, with generally requires graphic based support, like we’ve jupyter-notebooks, sypder etc. for python, or VsCode as integrated editor. We all have our favorites, but using them in containers requires graphics. That’s what we’re gonna do in this article, by providing graphical support to containers, via X11 socket of docker hosts. How ?

Very simple, requires only one step:

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

-e DISPLAY=$DISPLAY will inherit the display environment variable of my docker host. i.e. :~

-v /tmp/X11-unix:/tmp/X11-unix will mount Container’s unix X11 socket to docker host’s unix socket. Thus it can use the graphic support of base docker host.

Let’s see some hands-on as I’ll show to install jupyter-notebook and launch it with firefox browser from centos container.:

  1. Launching container with GUI support, with same command shown above,

2. Installing python36 & Firefox packages,

yum install python36 firefox -y

3. Confirming firefox running on centos container,

Great !!

Now let’s install Jupyter, and launch the notebook, from container.

Finally, launching GUI based I.D.E :~

Done !!

Similarly, you can use any graphical based editor, or even more, any tool software which requires graphic support with this method.

--

--

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