distrobox-logo

It’s no secret that the preferred way of obtaining new end-user software in Nitrux is to use AppImages, although we also support Flatpak. And that is because we’d prefer to keep the root clean and without surprises; in other words, we don’t make this distribution centered around a package manager but rather applications. Nitrux has included Docker for over two years, which aligns with that concept. Indeed, we understand that some users still want to use a package manager but haven’t used a container before; thus, Distrobox makes it easier to get started.

In today’s tutorial, we will create a container using Distrobox with Podman, install an application, and make the container use hardware acceleration.

Difficulty: ★★☆☆☆

📜 Table of Contents

  1. About Distrobox
  2. Accessing a Distrobox Container
  3. Enabling Hardware Acceleration for Applications on Distrobox
  4. Adding an alias to run software installed on Distrobox
  5. Troubleshooting

About Distrobox

Distrobox is based on an OCI image and implements concepts similar to ToolBox, built on top of Podman and OCI standard container technologies.

Here are some of the highlights of Distrobox.

  • Provide a mutable environment on an immutable OS, like Endless OS, Fedora Silverblue, OpenSUSE MicroOS, or SteamOS3.
  • Provide a locally privileged environment for sudoless setups (e.g., company-provided laptops, security reasons, etc.)
  • To mix and match a stable base system (e.g., Debian Stable, Ubuntu LTS, RedHat) with a bleeding-edge environment for development or gaming (e.g., Arch, OpenSUSE Tumbleweed, or Fedora with the latest Mesa.)
  • Leverage large, curated distro images for Docker/Podman to manage multiple environments.

Create a Container with Distrobox

The syntax to create a new container is as follows.

distrobox-create --name CONTAINER-NAME --image OS-NAME:VERSION

In this example, we will create a container called debian11-distrobox from a Debian 11 image.

For a complete list of operating systems and versions supported by Distrobox containers, visit the Distrobox Project page.

  • The command below pulls the Debian 11 image from DockerHub and creates a container called debian11-distrobox.
distrobox-create --name debian11-distrobox --image debian:11

To list containers created with Distrobox, run the following command.

distrobox-list

Accessing a Distrobox Container

Before entering the container, we must change the root propagation to shared.

  • Mount propagation allows for sharing volumes mounted by a container to other containers in the same pod or even to other pods on the same node.

We can check this value by running the following command.

findmnt -o PROPAGATION /

If the output reads private,” we cannot enter the container. To change this value, run the following command.

sudo mount --make-rshared /

To access the shell of the newly created Linux container, run the following command.

distrobox-enter --name debian11-distrobox

We can see that we’re inside the container as our hostname has changed to the container’s name. We can continue using the container or type “exit” to quit the container.

Running Software inside a Distrobox Container from the Host

Using Distrobox is unnecessary to enter the container to install or remove software; we can run the commands directly. For example, we will install Neofetch on the container without entering the container.

To do this, run the following command.

distrobox-enter --name debian11-distrobox -- sudo apt install neofetch --no-install-recommends

As before, we can either enter the container and run the program or use the command distrobox-enter.

distrobox-enter --name debian11-distrobox -- neofetch

Exporting Applications from a Container with Distrobox

We can export software if we have installed it inside a container. Exporting a program with Distrobox will make the specified software available to the host operating system as a native application.

To export an application, we must enter the container; once inside, we can run the following command.

distrobox-export –app $APP_NAME
  • It’s worth noting that the export command works when the software utilizes a desktop launcher (.desktop). For software that doesn’t use a desktop launcher (like neofetch, a CLI utility), we recommend entering the container or using the command distrobox-enter and creating an alias in the file ~/.zshrc.

In this example, we will use Blender and export it to be available in the host.

First, we need to install Blender.

distrobox-enter --name debian11-distrobox -- sudo apt install blender --no-install-recommends

And then, we can enter the container and run Blender to test that it works.

Once we know that it’s working, we can export the application.

distrobox-export --app blender

Once we do that, Blender will be available to launch from our application menu.

Enabling Hardware Acceleration for Applications on Distrobox

We need to perform the below steps to run applications installed in a container with Distrobox that require hardware acceleration like Blender. Other software can run without the steps below.

Instructions below are for the container used as an example for this tutorial and using Nitrux as the host; adapt to your needs if you’re using a different distribution.

If using the Nvidia proprietary driver, we need to have matching versions of the driver on the host and the container; otherwise, we will see an error in the container when attempting to run software like Blender. So, first, we need to install the driver package; when installing the package, we will use the option –no-install-recommends to avoid installing a kernel package in the container; this way, we avoid a problem with dkms; see below (*).

    • ⚠️  Important: Replace the version of the driver from this example (nvidia-driver-525 and 525.85.05) with the correct version number.
#### Use a cleaner sources.list and add a repository to install the Nvidia driver.

>> sources.list printf "%s\n" \
    '########################################' \
    '#   DO NOT EDIT THIS FILE!             #' \
    '#   Your changes will be overwritten   #' \
    '########################################' \
    '' \
    '#########################' \
    '# Debian Repos Unstable #' \
    '#########################' \
    '' \
    'deb [arch=amd64] http://deb.debian.org/debian stable main non-free contrib' \
    ''

>> gpu-ppa-repo.list printf "%s\n" \
    '########################################' \
    '#   DO NOT EDIT THIS FILE!             #' \
    '#   Your changes will be overwritten   #' \
    '########################################' \
    '' \
    '#######################' \
    '# Proprietary GPU PPA #' \
    '#######################' \
    '' \
    'deb [arch=amd64] http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu focal main' \
    ''

sudo mv sources.list /etc/apt/sources.list

sudo mv gpu-ppa-repo.list /etc/apt/sources.list.d/

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1118213C

sudo apt update

sudo apt install nvidia-driver-525 --no-install-recommends

⚠️ (*) If a kernel is installed in the container, we will see an error with dkms because it will want to build the driver for both the host and the container kernels. So, we must tell dkms to skip building the driver for the host’s kernel. We need to locate the “dkms.conf” and edit it to do this. Inside the container, we need to run the following series of commands.

#### After dkms fails to build the driver, run the following command.

printf '%s\n' BUILD_EXCLUSIVE_KERNEL="^(4\.[0-9]+\.|5\.[0-9]\.)" >> /usr/src/nvidia-525.85.05/dkms.conf

sudo apt install -f

If using the MESA drivers (radeon, amdgpu, i945, iris, nouveau), we only need to install the following packages if the container doesn’t already have them.

sudo apt install libegl1-mesa libgl1-mesa-glx libvulkan1 mesa-vulkan-drivers

Adding an alias to run software installed on Distrobox

As we’ve seen, running software from Distrobox is super easy, but let’s say you don’t want to type all that text whenever you want to launch something. We can solve that quickly by creating an alias in ~/.zshrc.

We open the file with any text editor; for this example, we’ll use micro.

micro ~/.zshrc

Then we type the alias we want; in this case, we’ll create an alias for neofetch.

alias neofetch='distrobox-enter --name debian11-distrobox -- neofetch'

After doing so, we save and source the file, so our new alias works. So instead of typing the full Distrobox command, we only need to type neofetch to run it.

We can create an alias for anything we want, so if, as before, we only want to type “apt” instead of the full Distrobox command, we can create an alias. So let’s add an alias for APT.

We open the file with any text editor; for this example, we’ll use micro.

micro ~/.zshrc

Then we type the alias we want; in this case, we’ll create an alias for APT.

  • Please notice a space at the end, next to apt in our alias.
alias apt='distrobox-enter --name debian11-distrobox -- sudo apt '

After doing so, we save and source the file so our new alias works. So instead of typing the full Distrobox command, we only need to type apt to run it.

You will also notice that after adding this alias, we do not have to prepend APT with sudo; we run apt [option], for example, apt update instead of sudo apt update. And the reason for that is that we’re not running an APT binary from our root to make changes to our root; we’re running the binary from the container, which is rootless.

Of course, you can do this for any other software, including other package managers you want to use. By using aliases, we have a lot of flexibility; we can create a “dbox-run” alias to launch any binary within the container we specify on our alias or use the container to launch a binary in our home.

By now, you know the gist.

alias dbox-run='distrobox-enter --name debian11-distrobox --'

So we can use our “dbox-run” command to run neofetch or any other binary using the libraries from the container.

Troubleshooting

While it doesn’t affect the container’s functionality, in this Debian container’s case, do the following to eliminate those Perl warning messages.

    • FYI, these messages appear because the host’s locale differs from the container’s.
      • This issue is not a bug in Nitrux or caused by Nitrux.
distrobox-enter --name debian11-distrobox -- sudo apt install locales
distrobox-enter --name debian11-distrobox -- sudo dpkg-reconfigure locales

We can check that the messages disappear when rerunning APT.

When using a Debian container, it may be the case that the package tzdata is upgraded or that other packages do something regarding timezone changes resulting in an error with dpkg.

umount: /usr/share/zoneinfo/Etc/UTC: target is busy.
E: Problem executing scripts DPkg::Pre-Invoke 'if findmnt /etc/localtime >/dev/null; then umount /etc/localtime; fi'
E: Sub-process returned an error code
  • Because of how Distrobox works, this might create a problem; however, this is an issue that the Distrobox developer(s) should resolve.

We can edit the file /etc/apt/apt.conf as a workaround.d/00_distrobox inside the container as a workaround to avoid that problem. To do that, run the following command inside the container.

  • FYI, many containers do not come with a text editor installed. In this example, micro was installed in the container.
sudo micro /etc/apt/apt.conf.d/00_distrobox

Then comment on the first two lines, save the file, and rerun APT.

Additionally, block upgrades to the package tzdata by adding a file to /etc/apt/preferences.d like so with the following content.

  • Adjust a=unstable and n=sid to match your image. If Debian 11 were used, it’d be a=stable and n=bullseye.
############################
#  Debian Package Priority #
############################

Package: tzdata
Pin: release o=Debian,a=unstable,n=sid
Pin-Priority: -1

That’s it; this concludes today’s tutorial.

guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments