Using podman instead of docker on Windows Subsystem for Linux (WSL 2)
Tags: docker, wsl, containers, podman
Published: 2020-07-12 16:44:18

With [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/) (WSL) version 2, running Linux containers is possible and easy. However, Docker does not work without the docker daemon running, [systemd](https://www.freedesktop.org/wiki/Software/systemd/) is usually used to govern this, and WSL typically does not have systemd running.

Enter [podman](https://podman.io/).

Podman is a drop-in replacement for the docker commandline tool. It is "daemonless" (in other words, does not require systemd or other service to run in the background), and is [backed by Redhat](https://www.redhat.com/en/blog/why-red-hat-investing-cri-o-and-podman). Podman also works well without root—in other words, containers can easily run in userspace.

> Note that it _is_ possible to run the docker daemon without systemd and on pretty much any WSL distribution, even without Docker Desktop. [I documented my working setup in a separate article.](https://dev.to/bowmanjd/install-docker-on-windows-wsl-without-docker-desktop-34m9) But I still favor podman for reasons noted in this article.

I use Fedora ([you may read more about how I installed Fedora on WSL](https://dev.to/bowmanjd/install-fedora-on-windows-subsystem-for-linux-wsl-4b26)). In my setup, I needed some minor configuration in order for podman to work properly, and to run rootless. Here are the steps I used.

## Installing podman

To install podman, follow [the official instructions](https://podman.io/getting-started/installation.html). Most likely, guidance for your distro should be included there.

A quick summary:

- Fedora: `sudo dnf install podman`
- Centos: `sudo yum --enablerepo=extras install podman`
- Debian 11 (bullseye) or later, or sid/unstable: `sudo apt install podman`
- ArchLinux: `sudo pacman -S podman` and then [tweaks for rootless](<https://wiki.archlinux.org/index.php/Linux_Containers#Enable_support_to_run_unprivileged_containers_(optional)>)
- Debian 10: see [the guide](https://podman.io/getting-started/installation.html) for how to set up `apt` to use the [Kubic repos](https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/) then make sure to run `sudo apt update` then `sudo apt install podman`

## Set up $XDG_RUNTIME_DIR

Without systemd, the $XDG_RUNTIME_DIR was not available for podman to use for temporary files. I added the following to my `~/.bashrc` file:

```bash
if [[ -z "$XDG_RUNTIME_DIR" ]]; then
  export XDG_RUNTIME_DIR=/run/user/$UID
  if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
    export XDG_RUNTIME_DIR=/tmp/$USER-runtime
    if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
      mkdir -m 0700 "$XDG_RUNTIME_DIR"
    fi
  fi
fi
```

This script checks if the $XDG_RUNTIME_DIR is set, and, if not, sets it to the default systemd location (`/run/user/$UID`). If that does not exist, then set and create a temporary directory for the current user.

(Now source your .bashrc with `source ~/.bashrc` to update environment variables.)

## Use file logging and cgroupfs

Do you have `/etc/containers/containers.conf` or `~/.config/containers/containers.conf`? If so, great. On Fedora, and possibly other distributions, you may first need to copy `/usr/share/containers/containers.conf` to `/etc/containers` and/or `~/.config/containers`. Once the file exists, edit it, making sure that:

- `cgroup_manager = "cgroupfs"` (not systemd)
- `events_logger = "file"` (not journald)
- `log_driver = "k8s-file"` (not journald)

## Issue with shadow-utils on Fedora

On Fedora, I had to reinstall shadow-utils in order to have a properly installed `newgidmap` and `newuidmap`:

```bash
sudo dnf reinstall shadow-utils
```

## Test and prosper

The following should give you a simple command prompt:

```bash
$ podman run -it docker.io/library/alpine:latest
Trying to pull docker.io/library/alpine:latest...
Getting image source signatures
Copying blob df20fa9351a1 done
Copying config a24bb40132 done
Writing manifest to image destination
Storing signatures
/ #
```

Enjoy!

References:

- [How to Run Podman on Windows (Redhat SysAdmin blog)](https://www.redhat.com/sysadmin/podman-windows-wsl2)
- [Running rootless Podman as a non-root user (Redhat SysAdmin blog)](https://www.redhat.com/sysadmin/rootless-podman-makes-sense)
- [Podman rootless tutorial](https://github.com/containers/podman/blob/master/docs/tutorials/rootless_tutorial.md)