In the VM world, VirtualBox is an all-rounder doing everything good enough. But it often lags behind Linux kernel versions. It crashes when (un)docking a laptop, even in headless mode. It freezes when trying to enter the fullscreen mode on Wayland. Resizing the disk almost always results in a damaged image file. You can’t share files natively without running into permission issues. Nested KVM virtualization will never work within VirtualBox, obviously, but even USB passthrough isn’t that reliable. And worse of all, the software is made by a scummy corporation.
Docker is helpful or not, depending on the use case. You need to manage many config files, specify network port redirections, and create device nodes ahead of time. And you need to manually remove old containers and images. Rootless mode works only on the Linux hosts. Apps believe they run as root, so they may misbehave or not start at all. Browsers and webviews have compatibility issues. Full desktop won’t work because of disallowed kernel capabilities. Forget about snaps, appimages, or flatpaks. And worse of all, this is not a full isolation.
But only one of these approaches is useful if you work with coding agents that are unpredictable by design, or simply when you need a reproducible development environment. I need a reliable solution for my personal projects, with working USB serial and QEMU/KVM passthrough. So let’s try a rootless Debian container on a Ubuntu 26.04 host.
Table of Contents
Prerequisites
Install Docker rootless:
sudo apt install docker.io docker-compose-v2 rootlesskit
Disable the system service and the triggering socket:
sudo systemctl disable --now docker.socket
sudo systemctl disable --now docker.service
Add this line to ~/.bashrc:
export DOCKER_HOST=unix:///run/user/1000/docker.sock
Add yourself to the groups you need:
sudo usermod -aG dialout test
sudo usermod -aG kvm test
And reboot.
Starting rootless Docker on demand
Run the following command in a separate terminal, without sudo or root:
/usr/share/docker.io/contrib/dockerd-rootless.sh
Press Ctrl-C to stop the rootless Docker daemon.
If the script misbehaves:
- If there’s an error message telling that rootless Docker is already running,
killallany existingdockerdprocesses- If container works, but there’s no network, make sure the rootless Docker script is actually running, not just the stray
dockerdprocess
Creating sandbox files
Create a new sandbox directory. Inside, create device node files that point to
character devices of KVM (/dev/kvm) and USB serial (/dev/ttyACM0), and set
correct permissions:
sudo mknod dev_kvm c 10 232
sudo mknod dev_ttyACM0 c 166 0
sudo chown 1000:1000 dev_kvm dev_ttyACM0
chmod 0600 dev_kvm dev_ttyACM0
Tip: run
ls -l /devto find the major and minor numbers. Check the kernel docs as well.
This is the smallest usable Dockerfile, with:
- the XFCE4 core desktop, essential accessories, and basic fonts and themes
supervisorstarting two parallel processes:xrdpandxrdp-sesman- basic system configuration: root password and timezone
FROM debian:13
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install xfce4-session xfce4-panel dbus-x11 -y \
&& apt-get install xfce4-terminal thunar thunar-archive-plugin engrampa mousepad -y \
&& apt-get install greybird-gtk-theme elementary-xfce-icon-theme fonts-liberation -y
RUN apt-get install xrdp supervisor -y
RUN <<EOF
cat > /etc/supervisor/conf.d/xrdp.conf <<CONF
[program:xrdp]
command=xrdp --nodaemon
user=root
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
CONF
sed -e 's/xrdp/xrdp-sesman/g' /etc/supervisor/conf.d/xrdp.conf > /etc/supervisor/conf.d/xrdp-sesman.conf
sed -i -e 's/fork=true/fork=false/g' -e 's|LogFile=xrdp.log|LogFile=/dev/stderr|g' /etc/xrdp/xrdp.ini
EOF
RUN echo "root:mypassword" | chpasswd
RUN echo "TZ=Europe/Warsaw" >> /etc/environment
EXPOSE 3389
CMD ["supervisord", "--nodaemon", "-c", "/etc/supervisor/supervisord.conf"]
Now add this compose.yml to set everything up. Example:
services:
main:
build: .
ports:
- "127.0.0.1:3389:3389"
ulimits:
nofile:
hard: 131072
soft: 131072
volumes:
- ./dev_kvm:/dev/kvm
- ./dev_ttyACM0:/dev/ttyACM0
- ./data:/root
- /home/user/workspace:/shared/workspace
This is the final directory structure:
-rw-r--r-- 947 Dockerfile
-rw-r--r-- 284 compose.yml
crw------- 10, 232 dev_kvm
crw------- 166, 0 dev_ttyACM0
Starting the sandbox
Important: make sure you have firewall enabled, blocking incoming traffic on port 3389!
Open new terminal, go to the sandbox directory and simply run
docker compose up.
Use FreeRDP (the freerdp-x11 package) to connect to the “remote” session:
xfreerdp /v:127.0.0.1:3389 /u:root /p:mypassword /dynamic-resolution
Recommended UI tweaks
Make it look more like Xubuntu.
- Settings → Appearance
- Style: Greybird
- Icons: elementary Xfce (HiDPI)
- Fonts: Liberation Sans 10 / Liberation Mono 10
- Settings → Panel
- remove Panel 2 (the bottom one)
- Settings → Window Manager
- Style - Theme: Greybird
- Style - Title font: Liberation Sans Bold 10
- Keyboard: clear the Alt-F12 shortcut for “Toggle above”
- Settings → Window Manager Tweaks
- Accessibility: uncheck “Raise windows when any mouse button is pressed”
Installing large software
If you want to install IDEs such as PyCharm or Android Studio, create a separate
packages directory, place the downloaded tar.gz file there, and add a few more
lines to the Dockerfile:
ARG STUDIO_VERSION=rabbit2-patch1
RUN --mount=type=bind,source=packages,target=/packages \
tar xf /packages/android-studio-${STUDIO_VERSION}-linux.tar.gz \
&& mv android-studio /opt/android-studio \
&& ln -s /opt/android-studio/bin/studio /usr/local/bin/studio \
&& rm -rf /tmp/*
I didn’t know you could just mount a local directory (read only) when building
Docker images. On the first attempt, I was going to curl and unpack in one
step, but it took 10 minutes every time I rebuilt the image. And what if one day
the file is removed from the server? Then I’ve tried COPY + RUN, but this
creates extra layers, and the build cache gets way too large.
Still, you should run docker builder prune -a if the build cache size becomes
a problem.
Known issues
Modern web is complex, so web browsers and webviews are run sandboxed. This requires kernel capabilities that are not available in rootless Docker containers.
Chromium must be run with the --no-sandbox command line argument.
MiniBrowser must be run with WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS=1
environment variable. (I use MiniBrowser for WebKit/Safari testing.)
In IntelliJ-based IDEs, such as PyCharm or Android Studio, some stuff like
Markdown rendering won’t work by default. Press Shift-Shift, type in registry,
choose the first option, and then:
- check
ide.browser.jcef.run-under-superuser.allowed - uncheck
ide.browser.jcef.sandbox.enable
I’ve also run into problems with KiCad, and I believe it’s caused by
JavaScript-adjacent stuff. It crashes when trying to create a new project,
with no useful error message. But projects can be created manually: just add an
empty project_name.kicad_pro file to a new directory.
Bonus: a basic GUI
I’ve asked my local LLM to generate a simple tray app for me, using Python and AppIndicator. After few agentic loops, I have a script that can start Docker and Compose environment without opening the terminal. I can also start new FreeRDP session. I don’t need to find commands in terminal history or use shell aliases, logs are saved to files as well.