DEV Community

Cover image for My dream come true: Launching GUI Docker sessions with DX11

Posted on • Updated on • Originally published at Medium

My dream come true: Launching GUI Docker sessions with DX11

Get ready, because today we will get you to launch complete Linux Desktop Environments on demand. You’ll create your ideal graphical environment in a few minutes and launch it in a few seconds. Launch any desktop in the same way as you would launch a program.

Sounds good, doesn’t it?

If you are a Linux user, at some point you may have used Virtual Machines to try new stuff and experiment before you choose one. Virtualization is cool, but you know the downsides:

  • You need to boot a separate OS with its own Kernel and added overhead
  • The guest OS preallocates a fixed amount of RAM memory, even if only 1% of it is used
  • Your guest OS will never run as smoothly as your native desktop
  • The guest OS also needs a virtual data partition, networking, guest tools, etc
  • You need to manually install it and tweak it to your needs
  • If an upgrade breaks your system, there is no clean way to go back. With snapshots you would lose the latest changes on your personal data, whereas uninstalling or downgrading is not guaranteed to work

A new hope: Docker

Something instantly “clicked” in my head when I first heard of Docker:

  • Run any Linux command from any OS image, reusing the same Kernel and system resources.
  • Run on disposable stateless containers that you could break and relaunch right after.

That’s so cool, why don’t we all live on Docker containers right now?

Docker is mainly intended for backend projects. It’s designed for the command line and targeted to run servers, daemons, compilers and so on. Docker empowers great pieces of software, but Desktop Environments are not one of them yet.

Enter x11docker

X11Docker is a feature rich script that addresses this problem. It does the heavy lifting to start an X11 server on the host system and makes Dockerized apps talk to it. So with it, you can run GUI apps from the Docker image that you like! 😃🎉

I’ve been using it for a month now. While I applaud the brilliant work that it has behind, my conclusion is that X11Docker is not a VM replacement.

Instead, I see it as a replacement for docker run .
A minimal VM-like scenario looks much more like:

Unless you make a script of it, I bet you’ll never use x11docker for it. And yet this does not even include home folder encryption, direct connectivity with the host, etc.

The missing piece: DX11

My yearn for multiple independent Desktop systems launched on demand kept growing until I decided to ditch the script above and program a full fledged tool that made my dream come true.

Photo by [Adam Whitlock]( on [Unsplash]( by Adam Whitlock on Unsplash

Without further ado, let me introduce DX11! 😃🎉
DX11 / CLI manager for X11 Docker Linux sessions

DX11 is a Linux program that allows you to run X11 Linux sessions with Docker. A “session” consists of a Docker image, a user home folder and settings like user data encryption or Tor networking.

DX11 combines the great performance of Docker on Linux with many of the features you’d get when running VM’s:

  • As fluid and fast as your native system
  • Reuse the same kernel, system memory and disk storage
  • Scriptable, 100% reproducible desktop environments
  • Immutable desktop systems (similar in concept to Silverblue)
  • Disposable and throwaway sessions
  • Independent home folder persistence for each session
  • Optional home folder encryption
  • Optional Tor networking
  • Unprivileged execution, with the option to attach separately as root
  • Isolated sandboxed environments

Use cases

The list grows pretty much as you imagination allows. But a few examples include:

  • Realistic distro hopping. Try a new distribution or desktop environment before you make it your daily driver. Evaluate the real performance instead of hoping that a native installation would be smoother.
  • Full portability. Copy your session’s data to a brand new computer, rebuild the Docker image and continue to work as if nothing ever happened.
  • Give your developers a reference workstation Dockerfile that they can still customize. Avoid the “works on my machine” problem.
  • Speed up the landing of new developers with an already functional toolkit.
  • Post your session’s Dockerfile on your StackOverflow question or GitHub issue. Let others reproduce the exact same environment you have when you encounter that nasty error.
  • Deprecation proof development environments. Your legacy React Native or Cordova setup is carved in stone. If an SDK upgrade breaks a project, nothing else will be affected. Rerun your stable image and npm install will keep working as usual.
  • Post your session’s Dockerfile on a public repo. Let others clone it, fork it and make it even cooler.
  • Evaluate bloated/unsafe software on a clone of your workstation and drop the changes when you are done experimenting.
  • Upgrade and downgrade at will, without the risk of losing any local data. Docker build will never interact with any session, even if it’s running.
  • Replace your all-in-one bloated computer with minimal isolated systems that you can use on demand. One for your sysadmin work, one for your side projects, one for gaming, one for anonymous browsing, etc.
  • Forget about multiple SSH key management by having a different session for each project, with its corresponding key files and credentials.
  • Cybercafes, where a Linux computer spins up a fresh disposable desktop when you pay for it and terminates it when you are done.
  • Record a screencast of that upcoming Gnome/KDE release and transfer the video file to your main system right away. No VirtualBox Guest Additions needed.
  • If you write extensions for KDE, Gnome, etc., you can publish a Dockerfile to let people run sessions with them preinstalled.

You name it. The more you use it, the more you realize the enormous potential it has.

Well, show me the money!

Create a session

Let’s create a simple Dockerfile that customizes a Deepin Linux base image with a few extra packages:

The hard work is already done in x11docker/deepin. All we need to do is adding the commands that we would manually run after installing the system ourselves. In this case, a few system tools and a browser.

Now, let’s create our first session with it:

  • This creates or updates a session named my-workstation

  • A Docker image is built from Dockerfile and my-workstation is linked to it

Run the new session

That’s even simpler:

This will switch to a new Virtual Terminal and start Deepin in a fraction of the time it would take to boot the entire OS.

Deepin Desktop Environment started by DX11Deepin Desktop Environment started by DX11

Do some work, create some files and log out. Run dx11 run my-workstation again. Your prior work is there, your desktop boots in seconds, your session has the exact software that you need and you can be confident that if something bad happens, you’ll be back to normal when you log back in.

How about a brand new Gnome session? No problem, let’s extend a Dockerfile from ubuntu:eoan and install a few packages that we need to use. Two commands (dx11 new and dx11 run) and two minutes later, our DX11 session looks like this:

Gnome Desktop running on Ubuntu 19.10. Started by DX11.Gnome Desktop running on Ubuntu 19.10. Started by DX11.

Et voilà! Would you like to do the same with Ubuntu Mate? No problem. We haven’t touched a single installer yet, but here is our third session in less than 10 minutes:

Mate Desktop started by DX11Mate Desktop started by DX11

That’s insane!

The last two screenshots are the result of tweaking the user settings a bit and adding a global menu. But in general, starting a session with an already built image will take less than 10 seconds.

Attach as root

While my-workstation is running, you can attach to it from your normal session:

This will give you a root console, which allows you to try and change whatever you like on the system.

  • If you log out of the system, any changes besides /home/user will be lost

  • You can consolidate them into your Docker image using docker commit if you like

More base images

You can see a few examples provided on the DX11 repo and you can also checkout the Docker Hub images contributed by the X11Docker team.


DX11 is far from a finished tool. There are still bits and pieces that need attention, but so far I’m excited to be writing an article like this 😃

  • If you like it, please give it a try today and provide valuable feedback so we all can benefit from it.

  • Also, feel free to explore these Docker Hub images, experiment with your ideal setup and submit Pull Requests with your examples

Future work

The next thing I’d like to see is a “Docker Hub” for desktop sessions. Docker Hub itself would do the trick for the image registry, but most DX11 users would expect screenshots, screencasts, comments, etc.

That would be a nice challenge to undertake.

More conclusions: NIM

In my last article I briefly explained that I was going to check out the Nim programming language and see what I could do with it.

Nim: from scripting to C code. The all-in-one language.

After the experience of building DX11, I’d like to share a few thoughts about it:

  • Nim is a nice and clean language
  • I’ve felt that the language is well thought out and it leads to writing nice code quickly
  • The compiler is fast and produces small, dependency-free binaries. Sometimes, error reporting could be better, but as a newcomer to Nim I’ve been able to quickly detect the root issues and get them fixed
  • However, the main drawback is the lack of a graphical debugger for the most common IDE’s. You can use CLI tools, but things are likely to be slower when working on complex projects
  • Although not as popular as NodeJS’s, Go or Rust, Nim has many libraries available for use on your project, covering the typical dependencies you may find in systems programming

In my opinion it’s worth giving it a try. I hope more people get involved so we can tackle bigger and more complex projects with it.

That’s it for today! I hope you enjoy the Christmas toy 🎁 and if you like it, please clap out loud 👏, show some love ❤️, subscribe and give DX11 a try!

Until the next time, take care!

Photo by [Simon Matzinger]( on [Unsplash]( by Simon Matzinger on Unsplash

Cover by Mike Meeks on Unsplash

Top comments (3)

roostercrab profile image

This is fantastic, I have been waiting for something like this to become available for the exact reasons you lay out here. I want to create a development environment for each project but I don't want to find a magic way to interface with it, I just want it to look like any other desktop. I honestly think that Docker as a company would have been a lot better off if they invested their effort into this sort of project, thank you for doing it and I can't wait to try it out!

stamper profile image
Alexander Toropov • Edited

hi! great article
Full portability. Copy your session’s data to a brand new computer, rebuild the Docker image and continue to work as if nothing ever happened.
how do I do so?

nkrueger profile image
Nils Krüger

Thanks for the great post! Do you currently recommend DX11 or DX11 Nim?