Key Takeaways

  • Distrobox allows you to run applications from different Linux distributions on your own computer, while still keeping them isolated.
  • It integrates containers with the host computer, allowing applications inside the container to access your home directory and share configuration files.
  • Distrobox gives you the ability to install and run applications that may be difficult to find or install on your own distribution.


Frustrated by an app’s absent or lagging uphold for your preferred distro? appreciate magic, Distrobox runs applications from different Linux distributions right on your Linux computer. They’re running on your computer, yet they’re in their own native distribution. We show you how it works.


The Problem With Regular Containers

Containers are a form of virtual machine. A traditional virtual machine has a complete installation of an operating system inside it. Often, they’ll have a desktop environment too, and you can use them just as though they were a physical computer.

A container, on the other hand, only contains the minimum amount of operating system and tools to run the programs that the container is dedicated to supporting.

Because containers are lightweight and computationally cheaper than traditional virtual machines, they can be launched very quickly and controlled programmatically. Scripts can control their creation, use, shut-down, and removal. This makes them ideal for such things as development and evaluate environments, and providing automatic scalability for cloud-based services.

Just as they are with virtual machines, the applications inside containers are isolated from the host system. That’s a good thing in most scenarios, but it’s a showstopper if you want to use a program that’s installed inside a container as though it’s installed on your own physical computer.

How Distrobox is Different

Distrobox is a way to create and supervise containers that are integrated with the host computer. You can run programs inside the container that appear on the desktop of the host computer. Those applications can access your home directory on the host computer, allowing them to save files in your actual home directory, and not inside the container.

It allows two copies of an application, one on your physical computer and one in the container, to share the configuration files of the host computer. So a browser in the container, for example, can use the bookmarks stored in the configuration files on your physical computer.

Distrobox containers also benefit from hardware pass-through. If you plug in a USB device, for example, the container can see it too.

You can select from a wide selection of Linux distributions when you create a Distrobox containers. And because you can install applications into the container using the container’s package manager, you can overcome difficulties you may have installing a package directly onto your own computer.

Perhaps a package is notoriously difficult to install on your chosen distribution, or the version in your repositories is outdated, or not in the repositories at all. You may be able to find a Flatpak for that application, or you may be happy to build it from source.

Distrobox takes away the pain, and gives you a way to install and run applications that are difficult to find or otherwise problematic for your distribution.

How to Install Distrobox

Distrobox uses either Docker or Podman as the underlying container management system. We’re going to use Docker. If you don’t already have Docker on your computer you’ll need to install it.

Installing Docker

Docker is available in the repositories of the major distributions. To install Docker on Ubuntu, use this command. They added the “io” to the package name to differentiate it from another application in the Ubuntu repositories that was already using the name “docker.”

 sudo apt install docker.io 
Installing Docker on Ubuntu with the apt command

On Fedora the command is:

 sudo dnf install docker 
Installing Docker on Fedora using the dnf command

On Manjaro you need to type:

 sudo pacman -S docker 
Using the pacman command to install Docker on Manjaro

On all distributions, you need to create a user group and add yourself to that group. This allows you to use Docker in a rootless fashion, which is more safeguard than giving Docker root access to your system.

We create the group with groupadd command.

 sudo groupadd docker 
Creating the docker user group on Ubuntu

Docker may have created the group for you. If that’s the case, you’ll be told it already exists. Either way, we need to add you to that group, using the usermod command.

 sudo usermod -aG docker $USER 
Adding a user to the docker group on Ubuntu

You’ll need to log in and out to activate your group membership.

Installing Distrobox

Installing Distrobox is even easier than installing docker. On Ubuntu, the command to use is:

 sudo apt install distrobox 
Using the apt command to install Distrobox on Ubuntu

On Fedora type:

 sudo dnf install distrobox 
Using the dnf command to install Distrobox on Fedora

On Manjaro, the syntax is:

 sudo pacman -S distrobox 
Using the pacman command to install Distrobox on Manjaro

Creating a Distrobox Container

We’re now ready to create a container. This step requires an image file. The Distrobox command downloads the image for us, so we need to know the web address our image resides at.

We can select the image we want to use from the list on the Distrobox website. The list is in alphabetical order by distribution name, starting at AlmaLinux and finishing at Void Linux.

Many distributions are available in several versions. For example, Fedora is available in versions 35, 36, 37, 38, and 39, and Fedora Rawhide is available too. Versions that have “toolbox” added to their name include a set of default programs. Those without “toolbox” are lightweight images.

We’re going to create an Arch Linux container. Copy the web address for the image you’re going to use, and paste it into the following command.

 distrobox create -i quay.io/toolbx-images/archlinux-toolbox:latest -n "Arch-Db-1" 
Creating an Arch Linux container with Distrobox

We’re using the Distrobox create command to create a container. The -i (image) option tells Distrobox which image to use. The -n (name) option sets a name for the container. It also becomes the host name for the virtual computer inside the container.

You’re prompted to download the image to your computer. Press Y and hit the Enter key.

Answering

All the downloads we tried were surprisingly fast. When you return to the command prompt, use the Distrobox enter command to launch and enter our new Arch Linux container.

 distrobox enter Arch-Db-1 
Launching a Distrobox container

There’s some housekeeping to be performed the first time the container is launched. On our evaluate machine this took one or two minutes.

The housekeeping performed on the first launch of a Distrobox container

When you’re returned to the command prompt, take a look at it. It’ll say the name of the container you’ve created and entered. You’re now inside an Arch Linux container.

Using Apps inside a Container on the Host

To demonstrate a point, we’ll use the Arch package manager, pacman, to install neofetch.

 sudo pacman -S neofetch 
Installing neofetch on an Arch Linux container

Running neofetch shows we’re inside an instance of Arch Linux, running on a VirtualBox virtual machine that we know is running Ubuntu.

The output of neofetch on an Arch Linux container

We can install any application in our container, either from the Arch repositories or from the AUR, and run them on our host computer.

Running the ls command shows the home directory of our Ubuntu host computer.

Listing the files in the host computer's home directory from inside an Arch Linux Distrobox container

We created a file called “MyUbuntuDocument.md” on our host computer, and it is visible and accessible inside our container.

Using Graphical Apps Inside a Container on the Host

Let’s install and run an application inside our Arch container that uses a graphical interface.

 sudo pacman -S opera 
Installing the Opera browser inside an Arch Linux Distrobox container

As soon as it is installed, we can type “opera” to launch the browser from our Arch Linux command prompt. But Distrobox lets us start the program from outside the container, from our host computer’s command prompt.

 distrobox-enter -T -n Arch-Db-1 -- "opera" 
Launching an application installed ina Distrobox container from the command prompt of the host computer

The -T (no tty) option supresses the creation of a new terminal window. -n (name) command tells Distrobox which container to look inside for the command. The “–” (end of arguments) option is a flag that tells Distrobox everything that follows is part of the command that should be launched.

Opera is launched and runs on your desktop as though you had installed it on the host computer.

The Opera browser running on an Ubuntu desktop, launched from an Arch Linux Distrobox container

To make life easier, the command to launch the application could be saved as an alias, or put inside a desktop file on the host computer.

It’s clear that the launched application has access to your host computer. By looking inside the “~/.config” directory on the host computer, we can see that an “opera” directory has been created. The browser is storing its settings on the Ubuntu host.

The opera config files are stored on the host computer, not in the Arch Linux Distrobox container

Other Useful Commands

To exit from a container, type “exit” and hit “Enter.”

Exiting from a Distrobox container

You’ll see the prompt return to that of your host computer. The container is still running though. If you want to shut down the container, use the stop command.

 distrobox stop Arch-Db-1 
Stopping a running container with the distrobox stop command

You need to confirm that you really do want to stop the container.

To see which containers you’ve created, use the list command.

 distrobox list 
Listing the Distrobox containers present on the host computer

Color is used to highlight which containers are running and which are not.

You can eradicate, as in delete, a container with the distrobox rm command.

 distrobox rm OpenSuse-1 
Removing (deleting) a Distrobox container

Any App, From Any Distribution

Because you can create as many containers as you wish, each of which can contain a different Linux distribution, and each container can contain any number of applications, the permutations are endless.

There’s no longer a reason to miss out on any application from any distribution.

Source link