cover

Using Podman instead of Docker on MacOS

sorcererxw

I've been using Docker Desktop for many years, and it's very handy, bringing a lot of convenience to development. However, there are still some aspects of Docker Desktop that are not satisfactory:

  • A payment is required to ignore updates (cannot be automatically updated through Homebrew when installed using Homebrew Cask)
  • Slow startup

For me, all I need is the Docker CLI part, not the GUI, Docker-Compose, so Podman is a pretty good alternative.

Installation

$ brew install podman

$ podman machine init // 初始化 Podman

$ podman machine start // 启动 Podman

With a simple command, you can configure Podman on your machine, and it also starts up relatively quickly.

$ time podman machine start

INFO[0000] waiting for clients...
INFO[0000] listening tcp://0.0.0.0:7777
INFO[0000] new connection from  to /var/folders/yt/h6dhsb1500098zqv1sv11knw0000gn/T/podman/qemu_podman-machine-default.sock
Waiting for VM ...
podman machine start
0.02s user 0.02s system 0% cpu 22.810 total

By using podman -h, you can see that Podman is compatible with most Docker commands, making the migration learning cost extremely low.

Image Name

The default registry for Docker is docker.io, so when pulling images, it supports shorthand image names:

docker pull mysql:8

However, Podman is not associated with docker.io, so if you need to pull images from docker.io, you need to use the full repository address:

podman pull docker.io/library/mysql:8

You can also achieve auto-completion like Docker through configuration, refer to:

Container image short names in Podman
When people approach me to talk about Podman and containers, I usually ask if they are familiar with Docker. Most people are, and the conversations quick...
https://www.redhat.com/sysadmin/container-image-short-names

Port Mapping

When we start a container, we often need to configure the mapping of the container port and the host port, such as:

docker run -d -p 6379:6379 docker.io/library/redis:6 

Docker is configured by default for TCP port mapping. However, in Podman, you need to actively specify the network type:

podman run -d -p 6379:6379/tcp docker.io/library/redis:6