Custom Distrobox Setup with Docker and Podman

Custom Distrobox Setup with Docker and Podman

Custom Distrobox Setup with Docker and Podman

This post walks through creating a custom Docker/Podman image for Distrobox, enabling seamless containerized Arch Linux environments with pre-installed tools.


What is Distrobox?

Distrobox is a command-line utility that allows you to create and manage containerized Linux environments. It leverages either Docker or Podman to create containers that integrate deeply with your host system. This means you can install and run applications from different Linux distributions (like Arch, Fedora, Ubuntu, etc.) directly from your terminal, without affecting your host system’s integrity. It’s particularly useful for developers who need specific toolchains or libraries that might conflict with their host distribution, or for users who want to experiment with different Linux environments without dual-booting or using virtual machines.


Docker vs. Podman: Choosing Your Container Runtime

Both Docker and Podman are powerful containerization tools, but they have key differences that might influence your choice:

  • Docker: Traditionally, Docker has been the most popular container platform. It uses a client-server architecture, where the Docker daemon runs in the background and manages containers. This daemon typically requires root privileges, which can be a security concern in some environments.

  • Podman: Podman is a daemonless container engine, meaning it doesn’t require a continuously running background process. This allows it to run containers as a non-root user, enhancing security and simplifying integration into existing user workflows. Podman also offers a command-line interface that is largely compatible with Docker, making it easy for users to switch.

    Podman Logo

When to choose which?

  • Choose Docker if: You are already heavily invested in the Docker ecosystem, require Docker Compose for multi-container applications, or are working in environments where a daemon-based approach is preferred or necessary.

  • Choose Podman if: You prioritize security and prefer running containers rootless, want a simpler architecture without a daemon, or are working on systems where Docker might not be pre-installed or is restricted. Podman is often favored in enterprise Linux environments for its security features and daemonless design.

Distrobox is flexible and can work with either, allowing you to pick the container runtime that best fits your needs and system setup.


🚀 Dockerfile Configuration

Here’s the optimized Dockerfile for building a feature-rich Arch-based Distrobox image:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
ARG UID=1000

# Create the user and add them to the 'wheel' group for sudo access
RUN useradd -m -u $UID -G wheel $USER

# Configure sudoers to allow the wheel group to run commands without a password
RUN echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel-group

# Switch to the new user and set the working directory
USER $USER
WORKDIR /home/$USER

# Install yay from the AUR
RUN git clone https://aur.archlinux.org/yay.git && \
    cd yay && \
    makepkg -si --noconfirm

# Clean up the build directory
RUN rm -rf yay

# Install essential tools
RUN yay --noconfirm -S \
    neovim \
    tmux \
    zsh \
    gemini-cli \
    opencode-bin \
    crush-bin \
    oh-my-zsh-git \
    oh-my-bash-git \
    amazon-q-bin \
    nano

# Set default shell
RUN sudo chsh -s /usr/bin/zsh $USER

# Clean package cache (requires root)
USER root
RUN pacman -Scc --noconfirm

# Return to non-root user
USER $USER

CMD ["/bin/bash"]

🐳 Docker Instructions

  1. Set environment variable
    1
    
    export DBX_CONTAINER_MANAGER="docker"
    
  2. Build the image
    1
    
    docker build -t db-ai .
    
  3. Create Distrobox container
    1
    
    distrobox create --name my-arch-box --image db-ai
    
  4. Enter the container
    1
    
    distrobox enter my-arch-box
    

🐳 Podman Instructions

  1. Build the image
    1
    
    podman build -t db-ai .
    
  2. Create Distrobox container
    1
    
    distrobox create --name db-ai --image db-ai
    
  3. Enter the container
    1
    
    distrobox enter db-ai
    

📌 Key Features

  • Pre-installs: Neovim, tmux, Zsh, Oh My Zsh, Amazon Q CLI, and more
  • Wheel group sudo permissions for automation
  • Clean image with minimal package cache
  • Zsh set as default shell

🧠 Why This Works

This configuration balances developer productivity with resource efficiency. The use of yay enables AUR package access while the cleanup steps keep the image size manageable. The wheel group setup allows automated scripts to run without password prompts, critical for CI/CD workflows.

Use this as a base for your personal development environment or customize further with your preferred tools! 🚀