How to use the command 'podman machine' (with examples)
The ‘podman machine’ command allows users to create and manage virtual machines running Podman. This command is included with Podman version 4 or greater and provides a convenient way to interact with virtual machines.
Use case 1: List existing machines
Code:
podman machine ls
Motivation: This use case allows users to view a list of existing machines that are available for management.
Explanation: The ’ls’ subcommand is used to list all existing machines.
Example output:
NAME DRIVER STATE URL PURPOSE
default kvm Running tcp://192.168.39.3:2376
Use case 2: Create a new default machine
Code:
podman machine init
Motivation: This use case is useful when users want to create a new default machine for running their Podman containers.
Explanation: The ‘init’ subcommand is used to create a new default machine. This machine will have default resources assigned to it.
Example output:
Creating KVM machine 'default'...
Use case 3: Create a new machine with a specific name
Code:
podman machine init name
Motivation: This use case allows users to create a new machine with a specific name, which can be helpful for organizational purposes.
Explanation: The ‘init’ subcommand is used to create a new machine with the specified name.
Example output:
Creating KVM machine 'name'...
Use case 4: Create a new machine with different resources
Code:
podman machine init --cpus=4 --memory=4096 --disk-size=50
Motivation: This use case is useful when users want to create a new machine with custom resource allocations such as CPU cores, memory, and disk size.
Explanation: The ‘init’ subcommand is used to create a new machine, and the given options (–cpus, –memory, –disk-size) are used to specify the desired resource allocations.
Example output:
Creating KVM machine 'default' with 4 CPUs, 4096MB memory, and 50GB disk size...
Use case 5: Start or stop a machine
Code:
podman machine start|stop name
Motivation: This use case allows users to start or stop a specific machine as needed.
Explanation: The ‘start’ or ‘stop’ subcommands are used to respectively start or stop the machine with the specified name.
Example output:
Starting machine 'name'...
Use case 6: Connect to a running machine via SSH
Code:
podman machine ssh name
Motivation: This use case allows users to connect to a running machine via SSH and execute commands within the machine.
Explanation: The ‘ssh’ subcommand is used to establish an SSH connection to the machine with the specified name.
Example output:
SSH connection established with machine 'name'.
Use case 7: Inspect information about a machine
Code:
podman machine inspect name
Motivation: This use case allows users to obtain detailed information about a machine for troubleshooting or administrative purposes.
Explanation: The ‘inspect’ subcommand is used to retrieve detailed information (such as configuration, state, etc.) about the machine with the specified name.
Example output:
{
"name": "default",
"driver": "kvm",
"state": "Running",
"url": "tcp://192.168.39.3:2376"
}
Conclusion
The ‘podman machine’ command provides a range of functionalities for managing virtual machines running Podman. By utilizing these use cases, users can efficiently create, manage, and inspect virtual machines to optimize their containerized workflows.