How to install Podman on Ubuntu 20.04 WSL2

Podman is the open-source project developed by RedHat to run Containers on Linux operating system. It is daemon less container command line platform to create, manage and delete containers using docker and other supported Images. It is a drop-in replacement for Docker. Well, for those who are on Windows 11 or 10 using Ubuntu 20.04 LTS WSL2 and want to install & use Podman Containers, here is the tutorial for them.

WS2 is the upgraded version of WSL1 (Windows Subsystem for Linux) that uses the Virtual Machine Platform feature of Windows 10 or 11 to run Linux Apps like the native one.

Install Podman on WSL2 Ubuntu 20.04 – Windows 10 or 11

If you are already running a Ubuntu 20.04 LTS WSL2 app on your Windows 10 or 11 then jump to step 3 of this tutorial, where we have shown the command for Podman installation. Otherwise, go through all steps.

1. Enable WSL and Virtual Machine Platform

Those who yet have never used the Windows subsystem for Linux, need to first enable the same. Whereas WSL1 can be used without the Virtual machine Platform feature but WSL2 cannot.

Command Line Method:

If you don’t want to use the GUI method then simply right-click on your Windows 11 Start menu icon and select “Windows Terminal (Admin)“. And type:

wsl --install

 

 

GUI Method:

• Click on the Windows Search icon or press the Start button on Keyboard.

• Now, type- features, when the “Turn Windows Features On or Off” option appears select to open it.

Turn Windows features on or off Windows 11

• On Windows Features, check the box given for “Virtual Machine Platform” and “Windows Subsystem for Linux“; hit the OK button.

Enable WSL and Virtual Machine Platform

Reboot system

Once the features are installed, reboot your Windows to make sure integration happened successfully.

 

2. Install Ubuntu 20.04 on Windows 11 or 10 WSL 2

Now, we have the basic platforms we required to run Windows Subsystem for Linux version 2, it’s time to install the Ubuntu 20.04 LTS Linux app either using the Microsoft store or Powershell.

There are two ways- CLI and GUI; Select the one which you feel comfortable with.

Command-line method:

If you would like to use the command line, then right-click on your Windows Start menu icon and select Powershell (Admin) or Windows Terminal (Admin).

wsl --install Ubuntu-20.04

To check other available Linux distros, the command is:

wsl --list --online

command to check other available WSL Linux distros

 

GUI Method:

If you want it via Microsoft Store, then click on its icon given in the Taskbar or search the same in the Programs. After that search for Ubuntu 20.04 LTS.

Command to install Ubuntu 20.04 WSL2

 

3. Launch Ubuntu 20.04 WSL2 to install Podman

In the next step, open your installed Ubuntu WSL app. It will take some time to finish the final setup and after that will ask you to set a username and password. Once done, first run the Update command:

sudo apt update

Next, Install Podman Container:

There are two ways to install Podman: First either upgrade your Ubuntu 20.04 to Ubuntu 20.10 LTS to get Podman without adding an additional repository. And the second one is to add the official repo of Podman manually to install the same on Ubuntu 20.04 LTS. Here we show both the methods.

#Ist Method:

Get Podman on Ubuntu 20.04 LTS using its repository:

Add the repository:

Paste the whole block of command:

echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /" |
sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list

Add the GPG key 

curl -L "https://download.opensuse.org/repositories/devel:/kubic:\
/libcontainers:/stable/xUbuntu_20.04/Release.key" | sudo apt-key add -

Run system update & upgrade to refresh Repo cache and install the latest version of available packages.

sudo apt-get update
sudo apt-get -y upgrade

Finally, use the APT package manager to install Podman:

sudo apt install podman

Command to install Podman on Ubuntu 20.04

 

#2nd Method by upgrading

If you don’t want to add any repository manually, then another way to install Podman is by upgrading Ubuntu 20.04 to Ubuntu 20.20 LTS. Because then after you will be able to get the packages to set this container platform via the official repositories.

Step 1: First use this article to upgrade your WSL2 running – Ubuntu 20.04 to Ubuntu 21.04 using Terminal.

Step 2: Once you’re on Ubuntu 20.10 LTS then simply run:

sudo apt install podman

 

4. Create Containers using Podman

The commands line used by the Podman is identical to Docker, hence if you have ever used it then you will not have any problem with Podman at all.

Pull Image:

Let’s say you want to create a container using Ubuntu Image available in the Docker Library. Then the command will be:

podman pull ubuntu

In the same way for Fedora use:

podman pull fedora

To list all pulled images:

podman images

 

Note: if you get a warning again and again while pulling the images: WARN[0000] “/” is not a shared mount, this could cause issues or missing mounts with rootless containers

Then run them otherwise leave it.

sudo chmod 4755 /usr/bin/newgidmap
sudo chmod 4755 /usr/bin/newuidmap

 

Create and run Container:

To create a container using any downloaded Images, use the below command syntax:

podman run -dit --name h2s fedora

In the above command, h2s is the name of the container we want to create while the fedora is the downloaded image.

Check whether it is running or not:

podman ps

Connect to running container command line or bash.

podman attach h2s

create container using podman on WSL 2

 

5. Use Docker as an alias to Podman

Those who still feel a little unfamiliar while using this container platform command line can alias it with Docker. But make sure you have only Podman installed on your system to use an alias command given below.

alias docker=podman

now, you can use all commands with “docker“.

docker --version

docker alias podman

 

For managing Podman using a Graphical user interface the users can go for Cockpit: How to Install Cockpit Web Console

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.