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 Docker, install an application and make the container use hardware acceleration.

Difficulty: ★★☆☆☆


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 a high abundance of 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 Docker.

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 Docker Hub and creates a container called debian11-distrobox.
  • To correctly create the container in Nitrux, we need to add “–root” to the command; otherwise, an error will occur due to permissions.
    • Distrobox will ask for your password every time you use the “–root” option.
distrobox-create --root --name debian11-distrobox --image debian:11

Running distrobox-create without the option “–root” will cause the command to fail, and after adding the option to the command, Distrobox successfully creates the container.

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

distrobox-list --root

Once again, the option “–root” is necessary.

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 --root --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.

Installing Software to a Distrobox Container

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

To do this, run the following command.

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

installing software on the container without entering it.

Exporting Applications from a Container with Distrobox

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

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

distrobox-export --app blender

Enabling hardware acceleration in Distrobox

We need to perform the steps below inside the container 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; however, at the end of the installation process, we will see an error with DKMS because it’s also trying to build the driver for the host kernel. So, we must tell “dkms” to skip building the driver for the host’s kernel. To do this, we need to locate the “dkms.conf” and edit it. Inside the container, we need to run the following command.
### Use a cleaner sources.list and add repository to install Nvidia driver

sudo >> /etc/apt/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' \
    ''

sudo >> /etc/apt/sources.list.d/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 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1118213C

sudo apt update

sudo apt install nvidia-driver-520

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

printf '%s\n' BUILD_EXCLUSIVE_KERNEL="^(4\.[0-9]+\.|5\.[0-9]\.)" >> /usr/src/nvidia-520.56.06/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

Troubleshooting

When first setting up Distrobox, you may encounter the error below.

Got permission denied while trying to connect to the Docker daemon socket at [....] unix /var/run/docker.sock: connect: permission denied

Run the following command, then log out and log in.

### Replace $USER with your user

sudo groupadd docker
sudo usermod -G docker -a $USER

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

guest

0 Comments
Inline Feedbacks
View all comments