In this first section I detail some of the terms I have used:

Dockerized graphical applications: A Docker container run from a Docker image which runs an application which (traditionally) uses x11 (or similar) to display the application on the host machine. More details in second section.

packages required for display remotely on clients: For example, a VNC server which allows a user of a local client (e.g. a laptop with desktop Ubuntu 18.04 installed) to navigate through the browser to an particular host-name and port.

In this second section I give an example of the usual way to run a Dockerized application, using gedit as an example:

Example Dockerfile:

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y gedit
CMD gedit

Example Docker build command:

docker build -t gedit:latest .

Example Docker run command:

Once-off (can potentially be a harmful command, use with caution):

xhost +local:docker


docker run --rm --name=gedit -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix gedit:latest

Please note: There are some security concerns running xhost +local:docker so to reverse this run xhost -local:docker

Sub-question / curiosity: The above installs x11, etc into the image. Is there any way to have a separate image with all of those dependencies and have multiple containers share folders in order to satisfy the x11 dependencies?

In this third section I detail an example in which my question is relevant:

I want to keep the Dockerized app as explained in section 2, which runs well locally on a client's laptop but have it as part of a cluster of docker containers (using docker-compose for example) so that the image built from the dockerfile in section 2 is unmodified.

I want to include an additional container which has all the VNC and x11 packages required so that the client can run the application remotely.

Which mechanisms allow the above to take place?


1 Answer 1


You can't run a program running on x11 without a x11 buffer somewhere, be it vnc, xvfb or whatever. You will always need x11 libraries on the system running the program or it couldn't work at all. That's akin to trying to run a C program without libc on the system.

Using system libraries from a different container with a volume is a bad idea, as it create a hard dependency on both containers using the same libraries, and is likely to crash somewhere when both systems try to acquire a lock on the library to load it.

I assume with a lot of tweaks it should be doable, but the added complexity is a real footgun and create more dependencies than should exist.

  • Thank you. That is a reasonable explanation. So I guess what I am looking for then is the ability to build one image with gedit and x11 libraries (as I have done for an example). Then build a second image containing VNC, etc. Then share x11 socket shared between the two resulting containers. What I really want is the ability for privileged users to execute a script on their dev system, that actually spins up a containerized application on the server but passes the graphics on to their system.
    – dnk8n
    Nov 5, 2018 at 13:29
  • you should be able to do this with a docker-compose topology, where the dependencies between the applications are clear. See the Docker documentation for depends_on Nov 5, 2018 at 13:47
  • @DeanKayton X11 forwarding through ssh is made for that, I'd go with a user x11 server (like xming on windows for exemple) and launching the app against this display port, indeed you'll have to share it with the host.
    – Tensibai
    Nov 5, 2018 at 15:29
  • @BruceBecker I'm more worried by the lock status of the lib files than the share itself, it may work but I'd advise against trying anyway :)
    – Tensibai
    Nov 5, 2018 at 15:33
  • Personally I didn't need a dockerized ssh daemon because the host already had all of that configured. It is an interesting idea to have a fully dockerized solution on a server without even ssh activated, but that is actually beyond what I really needed. I have seen a few examples of how it can be done, but in all of them there is one huge container with 10+ processes running in one container. I am curious about a multi-container approach based off many light images. I have accepted this answer because it proposes a possible solution but advises not to go down that road, very thankful for that!
    – dnk8n
    Nov 7, 2018 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.