I often need to spin up a linux virtual machine for many reasons. Most often I’ve used VirtualBox, but sometimes it can be a bit tricky, especially if I need to share some resources between host and guest. This is where a tool like Distrobox comes in handy.
TO SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)
Distrobox allows deploying a mutable Linux container from the terminal window and running full GUI applications from the guest on the host from a simple container. Once deployed, these containers have access to host resources, such as the user’s HOME directory, external and USB storage devices, graphical applications (X11/Wayland), and audio. More importantly, going this route uses less system resources than, say, VirtualBox.
The only caveat is that Distrobox is only supported on Linux.
So how is it done? It’s actually quite easy.
What you will need
To do this, you will need a running instance of a Linux desktop and a user with sudo privileges. I will demonstrate on Ubuntu Desktop 20.04.
How to install Docker and curl
The first thing we need to do is install Docker. Connect to your desktop, open a terminal window and install both Docker and curl with:
sudo apt install docker.io curl -y
Once the installation is complete, start and enable the Docker service with:
sudo systemctl enable --now docker
Add your user to the docker group with:
sudo usermod -aG docker $USER
Finally, notify the system of the changes with:
newgrp docker
How to install Distrobox
With Docker and curl installed, you can now download the installer file with the command:
curl https://raw.githubusercontent.com/89luca89/distrobox/main/install > install
Give the installer file executable permissions with:
chmod u+x install
If the ~/.local/bin directory does not exist, create it with:
mkdir -p ~/.local/bin
Now we’ll run the installer (and tell it to install everything into the newly created ~/.local/bin directory) with:
./install -p ~/.local/bin
You should now see all Dockerbox commands in ~/.local/bin. However, this directory is not currently in our path, so we add it with:
PATH=$PATH:~/.local/bin
Close the terminal and reopen it.
How to create a new container with Distrobox
Let’s deploy the latest version of Arch Linux with Distrobox, to see how it works.
First, we need to pull the latest version of Arch from the repository with the command:
distrobox create --image archlinux:latest --name arch
Once the pull is complete, we can start and enter the container with:
distrobox enter --name arch
You should end up at the Arch Linux bash console. Now the fun begins. Let’s install Firefox in the running container with the command:
sudo pacman -S firefox
Answer all questions with the defaults and eventually, when the installation is complete, you will be returned to the terminal. Now we can run Firefox from the terminal window, only the browser window will appear on the host desktop. To do this, run the command (from the container):
firefox
The Firefox window will open (Figure A) and you can start browsing as if it was running on the host.
Figure A
If you’re not convinced (because Firefox is installed on both the host and the guest), let’s install something on the guest that isn’t on the host. Open a second terminal on the host and run the command:
atom
You should see that the command is not found (Figure B).
Figure B
Close Firefox and, back to the Arch container prompt, install the Atom text editor with:
sudo pacman -S atom
Once the installation is complete, start atom with the command (run on the guest):
atom
The Atom Editor should open (Figure C).
Figure C
Exit the container with:
exit
How to delete containers with Distrobox
When you’re done, you can either leave these containers running (and grab them as needed) or delete them. First, list all your running containers with:
distrobox list
Locate the container you wish to delete and do so with:
distrobox-rm --name CNAME
Where CNAME is the name of the container to delete.
And that’s all there is to deploying containers and running graphical applications from them using Distrobox. I’m sure you’ll find plenty of ways to use this awesome tool.
Subscribe to TechRepublic How to make technology work on YouTube for all the latest tech tips for professionals from Jack Wallen.