Simplicity is the ultimate sophistication, Anonymous
Code never lies, comments sometimes do, Anonymous

If you’ve used Arch Linux, you’re likely aware of how easy it is to inadvertently alter or even break your system. However, containerized environments provide a reliable solution by allowing you to create isolated environments for specific tasks. This keeps your main system intact and stable while still enabling you to explore, use, and experiment with different applications and configurations in containers.
Using containers provides several benefits, including:

# For Ubuntu:
sudo apt-get install distrobox
# For Arch Linux:
sudo pacman -S distrobox podman
# Distrobox allows you to create and manage containers on your favorite Linux distribution using either Docker or Podman.
Using Distrobox as a native user space environment is an excellent way to keep your system clean, organized, and stable, particularly if you’re not yet ready to switch to an immutable Linux desktop. Distrobox is a tool that enables you to create and manage containerized environments on your preferred Linux distribution, using either Docker or Podman. Remember that with mutable systems, any changes or configuration drifts are permanent, so isolating your applications in containers is a smart approach to system management.
Arch Linux is an excellent distribution for development due to its rolling release nature (frequent updates). Despite Arch being notoriously difficult and complex for beginners, Distrobox simplifies starting with it:
distrobox create -i archlinux.distrobox enter archlinux.sudo pacman -S code.distrobox-export --app code.Create, enter, and manage containers effortlessly with Distrobox commands:
# Create an Arch Linux Container:
distrobox create -i archlinux
# Limit container resources (CPU/memory)
distrobox create -i archlinux --name limited \
--additional-flags "--cpus=2 --memory=4g"
# Create a Debian container based on the bookworm image with additional packages pre-installed.
# The --init-hooks option allows you to run commands right after the container is created.
# In this case, it updates the package list and installs git and build-essential.
distrobox create -i debian:bookworm --init-hooks "apt update && apt install -y git build-essential"
# Access a Distrobox Container: distrobox enter container-name
# Enters the Arch Linux container.
distrobox enter archlinux
exit
Once you’re inside the container, you can install and update applications without affecting your host system. This isolation is one of the key benefits of using containers. Here are a few commands to get you started:
# Install applications within the container
sudo pacman -S vlc flameshot fastfetch nvim
# It installs several applications: VLC (media player), Flameshot (screenshot tool), fastfetch (system information tool), and Neovim (a hyperextensible Vim-based text editor).
sudo pacman -Syu gimp # It updates all installed applications in the container and specifically installs GIMP (an image editor).
sudo pacman -S libcanberra-pulse # It installs a library for PulseAudio sound server support.
If you prefer, you can run commands directly in the Distrobox container without accessing the shell each time: distrobox-enter nameContainer ‐‐ distrobox-export ‐‐app nameApp.
# Export single application (creates a .desktop file)
distrobox-enter archlinux -- distrobox-export --app vlc
distrobox-enter archlinux -- distrobox-export --app gimp
# Export CLI tools to host's PATH (e.g., neovim)
distrobox-enter archlinux -- distrobox-export --bin /usr/bin/nvim --export-path ~/.local/bin
Make sure you’re running this command from your host system, not from inside the container
Distrobox also provides commands for managing your containers effectively:
distrobox stop archlinux # Stop a container.
distrobox enter archlinux # Restart the container.
distrobox create --name arch2 --clone archlinux # Clone an existing container.
distrobox rm arch2 # Remove a container.
distrobox-list # List all containers.
distrobox-list --verbose # Inspect container status
podman logs archlinux # View container logs
distrobox-upgrade --all # Upgrade all containers' packages.
# Create an alias
alias firefox-ubuntu='distrobox enter archlinux -- firefox'
This last command, distrobox-upgrade ‐‐all, will enter each container, use its package manager, and perform an upgrade for each one.
# 1. It creates a new Distrobox container named pyenv using the Python 3.11 image.
# This isolates your Python environment from the host system. You can install any Python packages, even conflicting ones, without touching your system Python.
# Rollback-Friendly: Break something? Just delete the container and recreate it.
distrobox create -n pyenv -i python:3.11
# 2. Access the pyenv container, where you can install Python packages and run Python scripts.
distrobox enter pyenv
# Installing Packages Inside the Container
# 3. Upgrade pip. It ensures you have the latest version for managing Python packages.
pip install --upgrade pip
# 4. Install the Faker Library. It is widely used to generate fake data such as names, addresses, and text.
pip install faker
# 5. It exports the Python binary from the Distrobox container to a specified path on the host system (~/.local/bin).
# This allows you to run Python scripts from your host environment.
distrobox-export --bin /usr/local/bin/python --export-path ~/.local/bin
# 6. It exits the Distrobox container and returns you to the host system's shell.
exit
# 7. Navigates to the directory where the Python binary was exported.
cd ~/.local/bin
# 8. Creates a new Python script using Neovim.
nvim mypython.py
# 9. This Python script imports the Faker library and generates a fake name, address, and text, printing them to the console.
from faker import Faker
fake = Faker()
print (fake.name())
print (fake.address())
print (fake.text())
# 10. It runs the Python script using the Python environment in the Distrobox container.
nmaximo7@ubuntupluckyvm:~/.local/bin$ distrobox-enter pyenv -- python python.py
Sarah Smith
70648 Hall Trail Apt. 160
Rogershaven, ME 06333
Or only great prove page. Statement popular article. Reduce support occur be think small. Travel sing population air southern first ball.
Check show draw set. Sometimes option blue stay.
# Instead of using the Distrobox environment to execute your Python script, you can also run it directly from your host system.
# By calling python python.py from the host system, you leverage the exported Python binary from your Distrobox container.
nmaximo7@ubuntupluckyvm:~/.local/bin$ python python.py
Shane Stewart
653 Angie Route
Coreyburgh, FM 45620
Success son science left federal. Citizen question call stuff table discover order. Gun purpose billion avoid. Throw state game entire state long bit.
A frequent error when running GUI applications in a container is “Cannot open display”, which suggests that the GUI application cannot access the X server display. This issue generally arises due to problems with X11 forwarding or lack of permissions to access the X server.
To resolve this issue, ensure that your user is permitted to connect to the X server:
# Install xorg-xhost (if not already installed).
# On Arch Linux
sudo pacman -S xorg-xhost
# On Ubuntu/Debian
sudo apt install x11-xserver-utils
# Configure X11 permissions in your shell profile
# Edit your shell configuration file
vim .zshrc: # For zsh users
# OR
vim ~/.bashrc # For bash users
xhost +si:localuser:$USER
# Apply the changes.
# Reload your shell configuration
source ~/.zshrc # For zsh
# OR
source ~/.bashrc # For bash
xhost is a command used to control access to the X server. It allows you to add or remove users and hosts that can connect to the X server. + indicates that we are adding an entry to the access control list. +si:localuser:$USER, we are granting permission to the local user (the one specified by $USER) to connect to the X server.