Way to Expose GUI from Docker Container
Docker containers play an important role in modern software development. Having a CLI access to the container is common, but sometimes we need to expose a GUI from the docker container. Here is a tutorial.
Tutorial
Recap: CLI Access
Normally, we use the docker flag -it
(interactive &
tty) to access a tty of the container, which provides us a CLI access to
the container. For example, we can run a Ubuntu 22.04 image with the
command
1 | $ # create a docker container from image `ubuntu:22.04` |
GUI Access
We share the X11 socket between the host and the container to enable GUI access. This could be achieved by the following command:
1 | $ docker run \ |
Then the GUI application can be run in the container, exposing the GUI to the outside. For example, the Kate editor:
(The hostname of the container will be shown in the title bar.)
Some Extensions
VNC Server
Another way to expose the GUI is to use a VNC server. See https://medium.com/@gustav0.lewin/how-to-make-a-docker-container-with-vnc-access-f607958141ae.