OS-Level Virtualization - Containers

Distrobox – use Linux distributions in your terminal

There are lots of ways of running multiple operating systems simultaneously on the same local machine. One way is to use virtualization software such as VirtualBox. Another popular alternative is courtesy of containers.

Distrobox is software which creates and manages container-based development environments without root privileges. It lets you run a wide range of Linux distributions on a single host system.

It’s not reinventing the wheel. Distrobox is merely a rather sophisticated wrapper around Podman or Docker. Podman is a daemonless tool designed to find, run, build, share and deploy applications using containers and container images. Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.

What’s a container? A container is an operating-system-level virtualization method for running multiple isolated Linux systems on a control host using a single Linux kernel.

Distrobox integrates these containers within your host system. Among other things, this means you share the HOME directory of the user, external storage, graphical apps (X11/Wayland), audio, systemd journal, even down to things like aliases in your shell. This is a real time-saver from a configuration perspective.

Installation

There are packages available for a wide range of Linux distros. We mostly tested Distrobox with Ubuntu 23.04 as the host, although we’ve explored using Fedora and openSUSE as the host too.

The software is installed on Ubuntu with the following command.

$ sudo apt install distrobox

distrobox installation

Let’s now create a container holding the Arch distribution with the distrobox-create command:

$ distrobox-create --name arch --image docker.io/library/archlinux:latest

In Operation

We use the distrobox-enter arch command to fire up the newly created Arch container. Note the prompt at the top of the screen says sde@saturn. saturn is the hostname of our Ubuntu 23.04 host machine.

distrobox first run

After running the distrobox enter arch command, you’ll notice the prompt has changed to sde@arch. We are now in our Arch container with the same username, same HOME directory, access to the same filesystems (local and remote), and graphical apps run direct from the container without any configuration necessary. As the above image also shows, Distrobox has performed an initial setup.

Now that we’re running Arch, we can install software using Arch’s package manager pacman, and install software in the Arch User Repository with an AUR helper such as yay or paru. Software is installed in the container, so that it doesn’t pollute the host system. Specifically, containers are stored in ~/.local/share/containers/storage. This means that, for example, we can run stable versions of software on our host machine, and development versions in a container. A great way of experimenting with cutting-edge software. We’ll walk you through an example.

Let’s install yay, an AUR helper, in our Arch container.

$ sudo pacman -S git base-devel
$ git clone https://aur.archlinux.org/yay.git
$ cd yay
$ makepkg -si

We’ll pick an example application, the image editor GIMP. Our Ubuntu 23.04 host system provides GIMP version 2.10.34. Let’s install the unstable development version of GIMP (version 2.99.14) in our Arch container.

$ yay -S libcanberra gimp-devel

We can use the distrobox-export command from the container so that the software we’ve installed is available to the host distribution.

$ distrobox-export --app gimp

Now, while we installed the unstable development version of GIMP inside the Arch container, it becomes visible in Ubuntu’s Applications Menu.

Distrobox
Click image for full size

We can, of course, still run the installed version of GIMP direct from the Arch container. But the beauty of distribox-export is that we can run the unstable development version of GIMP from the Ubuntu Application Menu without even needing to enter the Arch container via the distrobox-enter command ourselves. In other words, using distrobox-export from inside the container let you use them from the host itself.

distrobox-export copies the original .desktop files along with needed icons, adds the prefix /usr/local/bin/distrobox-enter -n distrobox_name -e … to the commands to run, and save them in our home to be used directly from the host as a normal app.

We can think of many examples of software that are available in an Arch package with no corresponding package in Ubuntu and that are non-trivial to manually compile.

For example, we really like the Goggles Music Manager. The developer used to provide Ubuntu packages but the software went a few years without any code updates and no packages supporting recent releases of Ubuntu. However, throughout this time, there’s a working package available in Arch. From the Arch container, we can install Goggles Music Manager and add a menu entry to Ubuntu’s Application Menu with:

$ yay -S jack2 gogglesmm
$ distrobox-export --app gogglesmm

Maybe that’s not the best example, as the developer of Goggles Music Manager has restarted development and has plans to release an Ubuntu 23.04 package. But the broad principle still applies. When the Ubuntu 23.04 package is available we can uninstall gogglesmm from our Arch container with yay and delete the menu entry with the command $ distrobox-export --app gogglesmm --delete.

Summary

Distrobox is a really useful tool. We’ve really only touched the surface of what the software can do.

We’ve illustrated one use case for Distrobox; directly accessing the power of the AUR when running a non-Arch Linux distribution as the host (in our case Ubuntu, but it could be Fedora, openSUSE etc).

What makes Distrobox really useful? It makes containers that are tightly integrated with your workflow in probably the easiest way possible. The absolute minimum fuss and bother. Perfect!

There are other use cases that spring to mind. We can use Distrobox for:

  • Test environments greatly reducing the risk of polluting your host distribution;
  • Accessing distro images for docker/podman to manage multiple environments;
  • Giving flexibility if you’re running a Linux operating system that’s designed to be unchangeable and read-only;
  • Provide a locally privileged environment for sudoless setups (such as company-provided laptops).

Think of Distrobox as an alternative to running a ‘full-fat’ virtual machine. Remember that containers use the host kernel and lack some of the flexibility of a virtual machine. But if you want to run software with multiple Linux distros you’ll save the massive time and resource overhead that comes with virtual machines.

Distrobox supports all the main distributions and the project compiles a curated table of supported and tested container images which is another time-saver.

We strongly recommend that you read the project’s useful tips section of its GitHub repository.

Website: distrobox.privatedns.org
Support: github.com/89luca89/distrobox
Developer: distrobox contributors
License: GNU General Public License v3.0

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments