Skip to content

Instantly share code, notes, and snippets.

@vyta
Last active July 16, 2025 14:26
Show Gist options
  • Save vyta/4c52d299ed5e2aed80c0799a3d5789bd to your computer and use it in GitHub Desktop.
Save vyta/4c52d299ed5e2aed80c0799a3d5789bd to your computer and use it in GitHub Desktop.
Rootless containerd in WSL2 with Ubuntu 24.04

Rootless containerd in WSL

Ensure systemd is enabled for WSL

sudo apt-get update -y && sudo apt-get install systemd systemd-sysv -y

And ensure /etc/wsl.config contains the following:

[boot]
systemd=true

Check systemd status

systemctl --user is-active dbus

# if in-active
systemctl --user enable --now dbus
systemctl --user start dbus
systemstl --user status dbus

Get binaries

# containerd
sudo curl -sSL https://github.com/containerd/containerd/releases/download/v2.1.3/containerd-2.1.3-linux-amd64.tar.gz | tar xzv -C /usr/local

# runc
wget https://github.com/opencontainers/runc/releases/download/v1.3.0/runc.amd64 && sudo install -m 755 runc.amd64 /usr/local/sbin/runc

# cni plugins
sudo mkdir -p /opt/cni/bin
sudo curl -sSL https://github.com/containernetworking/plugins/releases/download/v1.7.1/cni-plugins-linux-amd64-v1.7.1.tgz | tar xzv -C /opt/cni/bin

# nerdctl, buildkit (required for vscode dev containers), and rootless dependencies (rootlesskit and slirp4netns)
sudo apt-get install -y slirp4netns uidmap iptables
sudo curl -sSL https://github.com/rootless-containers/rootlesskit/releases/download/v2.3.5/rootlesskit-x86_64.tar.gz | tar xzv -C /usr/local/bin
sudo curl -sSL https://github.com/containerd/nerdctl/releases/download/v2.1.3/nerdctl-2.1.3-linux-amd64.tar.gz | tar xzv -C /usr/local/bin
sudo curl -sSL https://github.com/moby/buildkit/releases/download/v0.23.2/buildkit-v0.23.2.linux-amd64.tar.gz | tar xzv -C /usr/local

Install/start containerd and buildkit

containerd-rootless-setuptool.sh install

# For vscode devcontainers
CONTAINERD_NAMESPACE=default containerd-rootless-setuptool.sh install-buildkit-containerd

Run container

nerdctl run -it --rm alpine

OPTIONAL: Persist user processes even after logging out

loginctl enable-linger $(id -u)

Troubleshooting

  • Failed to connect to bus: No such file or directory when running systemctl --user commands. Try restarting the user systemd instance:
    sudo systemctl restart user@$(id -u)

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment