I frequently need to spin up a Linux virtual machine for numerous reasons. Most often I’ve used VirtualBox, but sometimes that can be a bit of a convoluted mess, especially if I need to share some resources between host and guest. That’s where a tool like Distrobox comes in handy.
SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)
Distrobox makes it possible to deploy a mutable Linux container from the terminal window and run full-blown GUI applications from the guest on the host from a simple container. Once deployed, those containers have access to host resources, such as the user’s HOME directory, external storage and USB devices, graphical apps (X11/Wayland) and audio. More importantly, going this route uses fewer system resources than, say, VirtualBox.
The one caveat is that Distrobox is only supported on Linux.
So, how is this done? It’s actually pretty easy.
What you’ll need
To make this happen, you’ll need a running instance of a Linux desktop and a user with sudo privileges. I’ll be demonstrating on Ubuntu Desktop 20.04.
How to install Docker and curl
The first thing we must do is install Docker. Log into your desktop, open a terminal window, and install both Docker and curl with:
sudo apt install docker.io curl -y
Once the installation completes, 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, make the system aware of the changes with:
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 install file executable permissions with:
chmod u+x install
If the ~/.local/bin directory doesn’t exist, create it with:
mkdir -p ~/.local/bin
Now, we’ll run the installer (and instruct it to install everything in the newly created ~/.local/bin directory) with:
./install -p ~/.local/bin
You should now see all of the Dockerbox commands in ~/.local/bin. However, that directory is not currently in our path, so we add it with:
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 this works.
First, we must pull the latest version of Arch from the repository with the command:
distrobox create --image archlinux:latest --name arch
Once the pull completes, we can start and enter the container with:
distrobox enter --name arch
You should find yourself on the Arch Linux bash console. Now the fun begins. Let’s install Firefox into the running container with the command:
sudo pacman -S firefox
Answer all of the questions with the defaults and eventually, once the installation completes, you’ll be returned to the terminal. Now, we can run Firefox from within the terminal window, only the browser window will appear on the host desktop. To do that, issue the command (from within the container):
The Firefox window will open (Figure A) and you can start browsing as though it were running on the host.
If you’re not convinced (because Firefox is installed on both the host and guest), let’s install something on the guest that’s not on the host. Open a second terminal on the host and issue the command:
You should see the command is not found (Figure B).
Close Firefox and, back at the Arch container prompt, install the Atom text editor with:
sudo pacman -S atom
When the installation completes, start atom with the command (run on the guest):
The Atom editor should open (Figure C).
Exit out of the container with:
How to remove containers with Distrobox
When you’re finished, you can either leave those containers running (and enter them as needed) or remove them. First, list out all of your running containers with:
Locate the container you want to remove and do so with:
distrobox-rm --name CNAME
Where CNAME is the name of the container to be deleted.
And that’s all there is to deploying containers and running GUI applications from them with the help of Distrobox. I’m confident you’ll find plenty of ways to make use of this impressive tool.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
Source of Article