,

Those pesky system connections

Development of Podman 6 is heating up! I have another usability improvement to share with you that some people see when running the Podman CLI. This case usually came up when people had created multiple machines. It was also more prevalent on Macs where people were using both libkrun and applehv provider machines and attempting to boot back and forth.

First, I’ll give an example of the common problem:

$ podman -v
podman version 5.7.0-dev

In Podman 5, consider a scenario where you have a machine created, maybe even the default machine.

$ podman machine ls
NAME VM TYPE CREATED LAST UP CPUS MEMORY DISK SIZE
podman-machine-default* libkrun About a minute ago Never 6 2GiB 100GiB

But for whatever reason, you want to create and use a new machine. To do this, you would use podman machine init and here I have passed the --now command line flag to instruct Podman to start the machine after creating it.

$ podman machine init --now new-machine
Looking up Podman Machine image at quay.io/podman/machine-os:5.7 to create VM
Extracting compressed file: new-machine-arm64.raw: done
Machine init complete
Starting machine "new-machine"

Machine "new-machine" started successfully

The new machine is now running and if I were to check what containers are running with podman ps, I would get the following:


$ podman ps
Cannot connect to Podman. Please verify your connection to the Linux system using podman system connection list, or try podman machine init and podman machine start to manage a new Linux VM
Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:49320: connect: connection refused

The reason is because Podman interacts with all non-localized instances by using a system connection. When you create your first Podman machine, we set that machine’s system connection as the default. But any subsequent new machines do not alter the default system connection. To view the system connections, use the podman system connection ls command.

$ podman system connection ls
Name URI Identity Default ReadWrite
new-machine ssh://core@127.0.0.1:49340/run/user/501/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true
new-machine-root ssh://root@127.0.0.1:49340/run/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true
podman-machine-default ssh://core@127.0.0.1:49320/run/user/501/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine true true
podman-machine-default-root ssh://root@127.0.0.1:49320/run/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true

And indeed, the default connection is set to podman-machine-default. This can be easily corrected by setting the correct system connection as the default.

$ podman system connection default new-machine
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

In Podman 6, we have closed this usability issue by altering Podman’s behavior when any machine is started. If we take a step back and try to run podman machine init –now new-machine, but with Podman 6 this time, the user will be prompted about setting the default connection to the new machine.

$ podman -v
podman version 6.0.0-dev
$ podman machine ls
NAME VM TYPE CREATED LAST UP CPUS MEMORY DISK SIZE
podman-machine-default* libkrun About a minute ago Never 6 2GiB 100GiB
$ podman machine init --now new-machine
Looking up Podman Machine image at quay.io/podman/machine-os:6.0 to create VM
Extracting compressed file: new-machine-arm64.raw: done
Machine init complete
Starting machine "new-machine"
Warning: The machine being started is not set as your default Podman connection.
As such, Podman commands may not work correctly.
Set the default Podman connection to this machine? [y/N] y

Default system connection will be changed to "new-machine"
… <omitted for brevity>

Machine "new-machine" started successfully

And Podman now works correctly.

$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE

The system connection was indeed updated.

$ podman system connection ls
Name URI Identity Default ReadWrite
new-machine ssh://core@127.0.0.1:49396/run/user/501/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine true true
new-machine-root ssh://root@127.0.0.1:49396/run/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true
podman-machine-default ssh://core@127.0.0.1:49383/run/user/501/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true
podman-machine-default-root ssh://root@127.0.0.1:49383/run/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true

So far I have mostly used podman machine init –now for examples, but the podman machine start command has also changed. Note in the command help text for start the new option --update-connection or -u.

$ podman machine start --help
Start an existing machine

Description:
Start a managed virtual machine

Usage:
podman machine start [options] [MACHINE]

Examples:
podman machine start podman-machine-default

Options:
--no-info Suppress informational tips
-q, --quiet Suppress machine starting status output
-u, --update-connection Set default system connection for this machine

The logic for this option warrants some explanation. It works as follows:

  • When no -u is used, you will be prompted as seen before.
  • When set to false, you will not be prompted and the connection will not be updated.
  • When -u is used but no value is provided or it is set to true, you will not be prompted and the connection will be updated.

Important: When wishing to set this option to false, it must be used like -u=false. Note the use of the equal sign.

Assuming new-machine is not the default system connection and I want to start it, I can pass -u and it will be updated

$ podman machine start -u new-machine
Starting machine "new-machine"
… <omitted for brevity>

Machine "new-machine" started successfully

A quick peek at the system connections confirms the change.


$ podman system connection ls
Name URI Identity Default ReadWrite
new-machine ssh://core@127.0.0.1:49396/run/user/501/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine true true
new-machine-root ssh://root@127.0.0.1:49396/run/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true
podman-machine-default ssh://core@127.0.0.1:49383/run/user/501/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true
podman-machine-default-root ssh://root@127.0.0.1:49383/run/podman/podman.sock /Users/baude/.local/share/containers/podman/machine/machine false true

And podman ps runs successfully.

$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

In:

,

Leave a Reply

Subscribe

Sign up with your email address to receive updates by email from this website.

Go back

Your message has been sent

Warning
Warning
Warning.

Categories


Search