DEV Community

podman machine on mac OSX 12.0.1 (Monterey)

Podman is a drop in replacement for Docker, and can handle containers daemonless and rootless ("ruthless"?). Containers work based on cgroups, namespaces and IPC, which is existing in Linux, and therefore requires a linux system to support it (which is based on Fedora CoreOS, and runs in QEMU).

Setup

Much of the configuration depends on the existence of 'brew' on OSX. If you haven't got brew (homebrew) installed, you can do so using:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

In order to run the podman machine, the podman software needs to be installed (step 1), a virtual machine for running podman on linux needs to be created (step 2), and run (step 3).

1.Install podman

brew install podman
Enter fullscreen mode Exit fullscreen mode

2.Initialize podman machine

podman machine init
Enter fullscreen mode Exit fullscreen mode

3.Start podman machine

podman machine start
Enter fullscreen mode Exit fullscreen mode

Verify podman machine

Because the podman machine must run before it can run containers, it is useful to understand if the podman machine is running. This is done with 'podman machine list':

Up:

podman machine list
Enter fullscreen mode Exit fullscreen mode
NAME      VM TYPE     CREATED       LAST UP           CPUS    MEMORY     DISK SIZE
podman-m* qemu        17 hours ago  Currently running 1       2.147GB    10.74GB
Enter fullscreen mode Exit fullscreen mode

Down:

podman machine list
Enter fullscreen mode Exit fullscreen mode
NAME      VM TYPE     CREATED       LAST UP           CPUS    MEMORY      DISK SIZE
podman-m* qemu        17 hours ago  3 seconds ago     1       2.147GB     10.74GB
Enter fullscreen mode Exit fullscreen mode

Containers & yugabyte

This setup is ideal for developers who want an easy way to setup YugabyteDB without all the hassle of configuration.

Any type of work with podman with containers requires the podman machine to be running. The podman machine is what actually performs the container commands.

For any type of coordinated work it's important to select a version to work on for the software you are using. Using the latest version can be a different version in time, and can cause version sprawl, so I would strongly recommend always choosing a specific version.

Obtain the yugabyte docker versions available:

curl -L -s 'https://registry.hub.docker.com/v2/repositories/yugabytedb/yugabyte/tags?page_size=5' | jq '."results"[]["name"]'
Enter fullscreen mode Exit fullscreen mode
"2.6.7.0-b10"
"2.11.0.0-b7"
"2.4.8.0-b16"
"2.6.6.0-b10"
"2.8.0.0-b37"
Enter fullscreen mode Exit fullscreen mode

Please mind the jq executable is not installed by default on OSX, but can easily be installed using brew:

brew install jq
Enter fullscreen mode Exit fullscreen mode

From the above versions, choose one to use, and obtain the image of the selected version in the following way:

podman pull yugabytedb/yugabyte:2.11.0.0-b7
Enter fullscreen mode Exit fullscreen mode
Resolving "yugabytedb/yugabyte" using unqualified-search registries (/etc/containers/registries.conf.d/999-podman-machine.conf)
Trying to pull docker.io/yugabytedb/yugabyte:2.11.0.0-b7...
Getting image source signatures
Copying blob sha256:486c41cfe6bf41372e1fbbe5e644b65e27a0d088135dbd3989721cb251147731
...snipped for brevety...
Copying blob sha256:ea30bbe39b88dfca4bdc2353505ea36c9322b8e9e17f969a0aedb1f058969f88
Copying config sha256:4f1f8156a955f434215a6f8ed01d782d61179c7624cc82a300c2f111c4fa7b51
Writing manifest to image destination
Storing signatures
4f1f8156a955f434215a6f8ed01d782d61179c7624cc82a300c2f111c4fa7b51
Enter fullscreen mode Exit fullscreen mode

Now a container can be started from the downloaded image:

podman run -d --name yugabyte-2.11 -p5433:5433 -p7000:7000 -p9000:9000 yugabytedb/yugabyte:2.11.0.0-b7 bin/yugabyted start --base_dir=/home/yugabyte/yb_data --daemon=false
Enter fullscreen mode Exit fullscreen mode
701422c063b46462c2b5bd573c117345f996e914325e26979829e506b8bc4362
Enter fullscreen mode Exit fullscreen mode

This takes a few moments to start.
When it has been started, the container and its status can be validated using podman ps:

podman ps
Enter fullscreen mode Exit fullscreen mode
CONTAINER ID  IMAGE                    COMMAND               CREATED         STATUS             PORTS                                                                   NAMES
701422c063b4  ../yugabyte:2.11.0.0-b7  bin/yugabyted sta...  37 seconds ago  Up 36 seconds ago  0.0.0.0:5433->5433/tcp, 0.0.0.0:7000->7000/tcp, 0.0.0.0:9000->9000/tcp  yugabyte-2.11
Enter fullscreen mode Exit fullscreen mode

If the container was successfully started, it will say 'Up' with the status. Also mind the name, which is important if you have got more than one container running.

One issue I found was that port 7000 was taken, which prevented the container from starting, because it wanted to use port 7000 on localhost. This was caused by: (OSX) system preferences>sharing>airplay-receiver, which is checked by default and needs to be unchecked.

After the container has started, it can be accessed from the CLI in the following way:

podman exec -it yugabyte-2.11 bash 
Enter fullscreen mode Exit fullscreen mode
[root@701422c063b4 yugabyte]#
Enter fullscreen mode Exit fullscreen mode

This allows you to investigate logfiles, process statuses, etc.

Stop the yugabyte container:

podman stop yugabyte-2.11
Enter fullscreen mode Exit fullscreen mode

Restart the yugabyte container:

podman restart yugabyte-2.11
Enter fullscreen mode Exit fullscreen mode

Please be aware that the yugabyte container must be stopped prior to stopping the podman machine. The podman machine might need to be stopped if no containers need running, and will be stopped if Mac is going to be turned off or restarted. If the yugabyte container is not stopped, it will leave a file in place indicating that yugabyte YSQL is running, which will prevent YSQL from starting up if the container is started again.

podman, containers and host restart

During the setup above, the podman machine has been initialized and is ready for use. After a host reboot, the podman machine doesn't need to be initialized again. However, the podman machine must be started after a reboot, it isn't started automatically:

podman machine start
Enter fullscreen mode Exit fullscreen mode

Once the podman machine is started, you can query the container statuses. By default containers are not automatically started on podman machine startup. To query the status of the containers including non-running containers, use the '--all' flag:

podman ps --all
Enter fullscreen mode Exit fullscreen mode
CONTAINER ID  IMAGE                    COMMAND               CREATED      STATUS                     PORTS                                                                   NAMES
701422c063b4  ../yugabyte:2.11.0.0-b7  bin/yugabyted sta...  2 hours ago  Exited (0) 10 minutes ago  0.0.0.0:5433->5433/tcp, 0.0.0.0:7000->7000/tcp, 0.0.0.0:9000->9000/tcp  yugabyte-2.11
Enter fullscreen mode Exit fullscreen mode

This shows that our yugabyte-2.11 container still is there, but it is not running. In order to use it, start the container:

podman start yugabyte-2.11
Enter fullscreen mode Exit fullscreen mode
yugabyte-2.11
Enter fullscreen mode Exit fullscreen mode

If we run podman ps again, we can validate the container is now running:

podman ps --all
Enter fullscreen mode Exit fullscreen mode
CONTAINER ID  IMAGE                    COMMAND               CREATED      STATUS                     PORTS                                                                   NAMES
701422c063b4  ../yugabyte:2.11.0.0-b7  bin/yugabyted sta...  2 hours ago  Up 40 seconds ago  0.0.0.0:5433->5433/tcp, 0.0.0.0:7000->7000/tcp, 0.0.0.0:9000->9000/tcp  yugabyte-2.11
Enter fullscreen mode Exit fullscreen mode

One way of using YSQL is to install postgresql on mac via brew (brew install postgresql). You can then run psql on the CLI directly to access YSQL in the container.

The database and its contents do survive stopping and starting the container, including if this has happened as part of a restart of the host. If a container is removed, the data is removed with it.

Remove podman machine

The podman machine running in qemu can be stopped, and removed:

podman machine stop
podman machine rm
Enter fullscreen mode Exit fullscreen mode

If the podman machine is removed, all the containers it hosted are removed with it.

The podman files are stored in the following place:
~/.config podman machine configuration file
~/.local podman machine disk image
~/.ssh podman machine private and public key

Containers and their configuration are stored inside the podman machine.

Top comments (0)