How to run Podman on Windows with WSL2

Want to run Podman on Windows 10? You can, thanks to the latest Windows Subsystem for Linux (WSL) 2.0 implementation.

source: https://www.redhat.com/sysadmin/podman-windows-wsl2

With the latest Windows Subsystem for Linux (WSL) 2.0 implementation, Podman now works out of the box. Minor changes to a configuration file make Podman more convenient to use. In the upcoming sections, I will document how I ran Podman under WSL2 and what configurations I changed to make things work smoothly.

At this time of this writing, WSL2 is only available as part of the Windows Insider program. As their documentation notes, you need to have at least Windows 10 build 18917. To set up WSL2, I followed Microsoft’s instructions.

Once I had the WSL environment installed, I then installed a Linux distribution from the Microsoft store. In this case, I chose to install Ubuntu.

[Editor’s Note: Red Hat distributions are not currently officially available in WSL.]Image

The results of cat /etc/os-release after installing Ubuntu.

Add the Podman PPA and install Podman

The easiest way to begin the installation of Podman on Ubuntu is to use the Kubic project as described in the installation documentation. You can easily add this package to your Ubuntu distribution:

. /etc/os-release
sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/x${NAME}_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/x${NAME}_${VERSION_ID}/Release.key -O Release.key
sudo apt-key add - < Release.key
sudo apt-get update -qq
sudo apt-get -qq -y install podman
sudo mkdir -p /etc/containers
echo -e "[registries.search]\nregistries = ['docker.io', 'quay.io']" | sudo tee /etc/containers/registries.conf

Because of WSL2’s unique environment, I recommend making changes to Podman’s configuration file. Otherwise, you will need to pass extra configuration options to each podman command. If you prefer this approach, you must pass the following to each incantation of podman:

--cgroup-manager cgroupfs --event-logger file

The two sections below describe how to make these changes permanent for rootless and privileged Podman users.

Rootless configuration file changes

If you plan to run podman as a non-root user, you should start with a simple podman command like:

$ podman info 

This action will create the Podman configuration file $HOME/.config/containers/libpod.conf. Simply edit this file and change the value of events_logger to <file>.

Rootfull configuration file changes

If you wish to run podman as a privileged user, you should first copy the Podman configuration file to /etc/containers/.

$ sudo cp /usr/share/containers/libpod.conf /etc/containers

Now, edit the version in /etc/containers and change the value of cgroup_manager to cgroupfs. Then, uncomment the line for the events_logger key and change the value to <file>.

The following is a simple diff of the changes:

27c27
< cgroup_manager = "systemd"
---
> cgroup_manager = "cgroupfs"
109c109
< # events_logger = "journald"
---
> events_logger = "file

Gotchas

Remember that WSL2 is still an experimental environment, and as such, not everything in Podman will work correctly. For example, I made changes to disable SystemD-related features in the Podman configuration file. I have not tested the ability to use SystemD in a WSL distribution for controlling containers. SystemD is also used by Podman for container health checks. This feature has also not been tested.

========================Debian=========================

. /etc/os-release

echo 'deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
 
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_${VERSION_ID}/Release.key | sudo apt-key add -

sudo apt-get update -qq

sudo apt-get -qq -y install podman

sudo mkdir -p /etc/containers

echo -e "[registries.search]\nregistries = ['docker.io', 'quay.io', 'registry.access.redhat.com', 'registry.fedoraproject.org', 'registry.centos.org']" | sudo tee /etc/containers/registries.conf 

sudo podman --cgroup-manager=cgroupfs --events-backend=file run --net=host -it alpine sh

mkdir -p $HOME/.config/containers
cp /usr/share/containers/containers.conf /home/sy/.config/containers/libpod.conf


cp /usr/share/containers/containers.conf /home/sy/.config/containers/containers.conf

have to read this one too.

With podman, run podman info to check the storage driver podman uses. Look for graphDriverName in the output. In my case, podman used vfs. Although vfs is well supported and runs anywhere, it does full copies of layers (represented by directories on your filesystem) in the image which results in using a lot of diskspace. If the disk is not super fast, this will result in long wait times when pulling an image and waste of disk space.

Without getting bogged down in the specifics of the storage drivers and their pros and cons, I decided to switch Podman from vfs to fuse-overlayfs. Fuse stands for Filesystem in Userspace, so fuse-overlayfs is the implementation of overlayfs in userspace (using FUSE). It supports deduplication of layers which will result in less consumption of disk space. This should be very noticeable when pulling a large image.

IMPORTANT: remove the containers folder in ~/.local/share to clear out container storage before installing overlayfs. Use the command below;

1rm -rf ~/.local/share/containers

faced few issues. below link help (ERRO[0057] unable to write pod event: “write unixgram @00017->/run/systemd/journal/socket: sendmsg: no such file or directory”)

https://github.com/containers/podman/issues/4325

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s