Podman using Ubuntu WSL2

The Docker Desktop for Windows is no longer free for commercial usage, or at least in many cases. If your local development environment is Windows, and you're looking for an alternative, this article is for you.




"Docker Desktop remains free for small businesses (fewer than 250 employees AND less than $10 million in annual revenue), personal use, education, and non-commercial open-source projects.". Unfortunately, containerization is a foundation of most enterprise-level projects these days, which size causes the licence issue.  The commercial doesn't cost an arm and leg, even though it builds unnecessary concern and limitations.

Even if you use the WSL2 Linux image, you need to use the docker engine, which is a part of the Docker Desktop for Windows.

Podman as Docker

And here is the beautiful moment when Podman comes into the play. It's a root-less and demon-less solution, fully compatible with docker. If you have been ever concerned about the demon working in the context of the root, you don't have to worry about this anymore

If your project uses docker compose for orchestration, you can stay with the solution. The Podman is able to host the socket API (compatible with docker), which can be linked behind.

Please find the blog article: Replace Docker for Windows with Podman that describes the Podaman/WSL2 integration in detail.

Quick setup Podman and docker-compose

I've let myself compile the case into the single bash podman-quick.sh script. Get it free and execute it on your new WSL2 instance to feel the essence.  

Once executed, both, docker and docker-compose commands remain operational, even if there's no Docker for Windows installed on your Windows system.

#!/bin/bash
export NAME=xUbuntu
export VERSION_ID=20.04
export BASEPATH=/run/user/podman
export PID_FILE=$BASEPATH/podman.pid
export SOCK_FILE=$BASEPATH/podman.sock

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

podman system service --time=0 unix://$SOCK_FILE &  echo "$!" > $PID_FILE
until [[ -S "$SOCK_FILE" && $COUNTER -lt 0 ]]; do echo Wating $COUNTER &&  sleep 1 &&  COUNTER=$((COUNTER-1)); done
if [ -S $SOCK_FILE ]; then  sudo ln -sf $SOCK_FILE /var/run/docker.sock; fi
echo "podman service started, pid is $(cat $PID_FILE)"

# Validate Podman
docker run -dt -p 8080:80/tcp docker.io/library/httpd
curl http://localhost:8080 #... expected: <html><body><h1>It works!</h1></body></html>

# Validate Docker-compose
echo -e "version: '3' \nservices:\n  myalpine:\n    image: python:3.7-alpine" > docker-compose.yml
sudo docker-compose up
sudo docker-compose images #... expected: Image to be resent 'docker.io/library/python'


...to get this:



Comments

Popular posts from this blog

Automatization of test cases in SCRUM

AWS Partner: Cloud Economics Accreditation