Podman Basics Cheatsheet RedHat Developer
Podman Basics Cheatsheet RedHat Developer
Cheat sheet
Podman
This cheat sheet covers the commands used for working with Podman, a popular tool for managing containers.
Podman commands are mostly compatible with Docker. As stated on the Podman landing page, "Podman is a
daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy
applications using Open Containers Initiative (OCI) Containers and Container Images."
Podman, unlike Docker, does not require a daemon running as superuser (root). This means that Podman interacts
directly with the various components in the Linux container ecosystem instead of relying on a continuously running
daemon to intermediate between these components on the caller’s behalf. Podman does not run as root by default,
which reduces the potential for a security hazard. Also, Podman does not spawn containers as child processes, thus
making the containers it creates durable and independent of Podman.
Overall, Podman is an excellent alternative to Docker containers when you need increased security, unique identifier
(UID) separation using namespaces, and integration with systemd.
" Important
!
The $$ symbol that proceeds commands in the examples represents the command line prompt.
The following sections describe the Podman commands for working with image repositories.
podman images
podman images [options]
Example:
The following example lists all the container images stored on the local machine. Note that the local machine has
container images from two public container image repositories, quay.io and docker.io :
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
quay.io/ansible/ansible-runner latest 697a4af2d624 16 hours ago 738 MB
docker.io/library/mysql latest 6126b4587b1b 18 hours ago 525 MB
docker.io/library/redis latest f1b6973564e9 4 weeks ago 116 MB
docker.io/library/nginx latest c316d5a335a5 4 weeks ago 146 MB
developers.redhat.com redhat-developer @rhdevelopers
podman rmi
podman rmi [-f] <<image>:<tag>
Removes a local image from the local cache. Use the -f option to force removal. This command removes the image
only from the local system, not from the remote registry. The image can be specified by a name or a UUID.
Example:
The following example removes a container image with the UUID c316d5a335a5 from the container image repository
on the local computer:
c316d5a335a5
$ podman rmi [-f] c316d5a335a5
podman push
podman push <registry_url>/<username>/<image>:<tag>
Example:
The following example uses the podman build command with the -t option to create a local container image with the
podman build
name and tag quay.io/myrepo/customer_container:v1.
quay.io/myrepo/customer_container:v1 The result is shown in an abbreviated format. Thenpodman
the images
podman images command lists the created container image. Finally, a podman push command pushes the container
podman push
image to the remote repository, quay.io:
quay.io:
$ podman images
REPOSITORY TA IMAGE ID CREATED SIZE
quay.io/myrepo/customer_container v1 a6b028f25b45 4 days ago 1.02 GB
podman history
podman history [options] <image>:<tag>
Displays historical information about a container image that has been download and stored on the local machine.
developers.redhat.com redhat-developer @rhdevelopers
Example:
The following example is an excerpt of output from a podman history command that gets historical information
podman history
for the container image of the zipkin distributed tracing framework that was retrieved from the quay.io
zipkin quay.io container
image repository:
podman login
podman login [options] <image_registry_url>
Logs a user into a remote container image registry. The command prompts the user for a username and password.
Example:
The following example logs the user in to the quay.io container image repository:
podman logout
Logs out of the current container registry.
Example:
The following example logs the user out of the quay.io container image repository:
podman pull
podman pull [options] <remote_registry_url>/<username>/<image>:<tag>
Example:
The following example retrieves the latest version of the container image for the ansible-runner tool from the quay.io
container image repository:
podman search
podman search [options] <search_string>
Example:
The example that follows uses the registry entries defined in the file /etc/containers/registries.conf
/etc/containers/registries.conf as: shown in the
snippet below :
[registries.search]
registries = ["quay.io", "registry.fedoraproject.org", "registry.access.redhat.com",
"registry.centos.org", "docker.io"]
The following podman search command finds container images that include the string pinger . The response is
displayed in an abbreviated format:
Building images
The following sections describe the various Podman commands for building container images.
podman build
podman build [options] <image>:<tag> [-f <Dockerfile>]
Builds and tags an image using the instructions in a Dockerfile, which can be specified as a filename or a URL. The -f
option specifies the location of the Dockerfile. If the -f option is omitted, the command looks for a Dockerfile in the
current directory. Once the container image is built, it is stored in the container image repository on the local machine
Example:
The following example creates a container image using the default Dockerfile in the local directory. Then the
command podman images is used to list the container images stored in the local repository. The output of the
container image list is piped to grep to display only container images that have the string mynode :
The following example creates a container image using a file named Otherdockerfile :
podman tag
.
podman tag <image>:<tag> <image>:<new_tag>
or
Creates a new tag for an existing container image in the local repository.
developers.redhat.com redhat-developer @rhdevelopers
Example:
The following example first executes a podman images command to list existing container images on the: local machine.
The podman tag command is then executed against the image with the UUID a6b028f25b45 and applies the new tag
best . The container images are listed again to show the new tag.
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/othernode v1 600590954fc5 5 minutes ago 1.02 GB
localhost/mynode v1 a6b028f25b45 14 minutes ago 1.02 GB
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/othernode v1 600590954fc5 6 minutes ago 1.02 GB
localhost/mynode v1 a6b028f25b45 15 minutes ago 1.02 GB
localhost/mynode best a6b028f25b45 15 minutes ago 1.02 GB
The following sections describe the Podman commands for creating and running containers.
podman run
podman run [options] <repo>/<image>:<tag>
Runs a container based on a given <image>:<tag> pair. If the image exists on the local machine, that image will be used.
Otherwise, podman run attempts to get the container image from the remote repository specified in the command.
Example: :
The following example runs a container using the latest version of the container image for the distributed tracing tool
zipkin that is stored in the quay.io container repository. The -d option runs the container in the background in order
to free the terminal window to accept future input. The output from podman run is the containers UUID.
Then, the command podman ps -a lists the running containers. Because the zipkin container was not assigned a name
when it was created, the arbitrary name laughing_mahavira is assigned to the container:
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ea35aa9eda87 quay.io/openzipkin/zipkin:latest 3 min ago Up 3 min ago laughing_mahavira
The following example creates and runs the container using the ngnix:latest container image. The -d option runs the
container in the background. The --name option gives the container the name mywebserver .
After the container is created, the command podman ps -a lists the containers running on the local machine. Note that
the lists the containers running on the local machine. Note that the nginx container has the name mywebserver .
developers.redhat.com redhat-developer @rhdevelopers
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ea35aa9eda87 quay.io/openzipkin/zipkin:latest 6 min ago Up 6 min ago laughing_mahavira
90ac3eb5f5a6 docker.io/library/nginx:latest nginx -g… 4 sec ago Up 4 sec ago mywebserver
The following example creates and runs the container. The option —rm causes the container to be removed after it
exits.
After podman run executes, the command podman ps -a lists the available containers. Note that the nodejs container
is not listed. This is because the -rm option was used when running it. The nodejs container spun up, but because
there was no activity for it to execute, it exited. Once the container exited, it was removed from the local machine:
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
ea35aa9eda87 quay.io/openzipkin/zipkin:latest 15 minutes ago Up 15 minutes
ago laughing_mahavira
90ac3eb5f5a6 docker.io/library/nginx:latest nginx -g daemon o... 9 minutes ago Up 9 minutes
ago mywebserve
The following example creates and runs the container using the -it option. This option creates a terminal and
presents a command prompt within the container after the container gets up and running:
The following example creates and runs a container using the nginx:latest image. After the container is up and running,
the pwd command is executed against file system internal to the container to report its current working directory.
The output shows that the current working directory is the root ( / ) directory:
podman stop
.
podman stop [options] <container>
Gracefully stops a container from running. The container can be specified by name or UUID
Example:
The following example first executes podman ps -a to list all containers on the local machine. Note that the two
containers listed have a status of Up <n> minutes ago . The podman stop command is then executed against the
container that has the name mywebserver .
The command podman ps -a is called again. Both containers are listed, but the container named mywebserver has a
status of Exited (0) 3 seconds ago , which is the point in time when the command podman stop was called.
developers.redhat.com redhat-developer @rhdevelopers
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
ea35aa9eda87 quay.io/openzipkin/zipkin:latest 27 minutes ago Up 27 minutes ago
laughing_mahavira
90ac3eb5f5a6 docker.io/library/nginx:latest nginx -g daemon o... 21 minutes ago Up 21 minutes ago
mywebserver
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
ea35aa9eda87 quay.io/openzipkin/zipkin:latest 28 minutes ago Up 28 minutes ago
laughing_mahavira
90ac3eb5f5a6 docker.io/library/nginx:latest nginx -g daemon o... 21 minutes ago Exited (0) 3 seconds
ago mywebserver
podman start
.
podman start [options] <container>
Example:
The following example uses podman ps -a to list containers on the local machine. Note that the container
: named
mywebserver has a STATUS of Exited (0) 3 seconds ago . The container is stopped.
Next, the command podman start mywebserver executes to restart the container. Then podman ps -a is executed again.
Now the container named mywebserver has a status of Up 31 seconds ago . The container has been started and is running.
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
ea35aa9eda87 quay.io/openzipkin/zipkin:latest 28 minutes ago Up 28 minutes ago
laughing_mahavira
90ac3eb5f5a6 docker.io/library/nginx:latest nginx -g daemon o... 21 minutes ago Exited (0) 3
seconds ago mywebserver
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
ea35aa9eda87 quay.io/openzipkin/zipkin:latest 33 minutes ago Up 33 minutes ago
laughing_mahavira
90ac3eb5f5a6 docker.io/library/nginx:latest nginx -g daemon o... 27 minutes ago Up 31 seconds ago
mywebserver
The following example runs the container image docker.io/library/nginx . The -d command runs the container in the
background. The --name option gives the container the name mywebserver . The -p option assigns port number 8181
running on the local computer (localhost) to the port number 80 , which is where the NGINX web server within the
container is listening for income requests:
developers.redhat.com redhat-developer @rhdevelopers
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4b59499314f docker.io/library/nginx:latest nginx -g… 8 sec ago Up 7 sec ago 0.0.0.0:8181->80/tcp mynginx
podman create
.
podman create [options] </repo/image:tag>
Creates a container from a container image but does not start it.
Example:
The following example creates a container from the quay/redis image found on the quay.io container image
: repository:
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dcc2491a3d16 quay.io/quay/redis:latest conf/redis.conf 3 seconds ago Created myredis
podman restart
.
podman restart [options] <container>
Example:
The following example uses podman ps -a to list the containers installed on the host computer. Note that
: the status of
the container named myredis is Created .
Then the podman restart command is used to start the container named myredis . Finally, the podman ps -a command is
called again. The status of the container is now Up 8 seconds ago , hence the container is running.
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
dcc2491a3d16 quay.io/quay/redis:latest conf/redis.conf 22 hours ago Created
myredis
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
dcc2491a3d16 quay.io/quay/redis:latest conf/redis.conf 22 hours ago Up 8 seconds
ago myredis
developers.redhat.com redhat-developer @rhdevelopers
podman rm
podman rm [options] <container>
Removes a container from the host computer. The container can be specified by name or UUID.
Example:
The following example uses podman ps -a list the containers installed on the host computer. Note that the
: container
named myredis is running. Then the command podman rm with the -f option forces the removal of the running
container named myredis . Finally, podman ps -a is called again. Note that the container has been removed from the
computer.
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
dcc2491a3d16 quay.io/quay/redis:latest conf/redis.conf 22 hours ago Up 8 seconds
ago myredis
$ podman rm -f myredis
dcc2491a3d16809c5c7b939e48aa99ded40779cb79140b1b9ae8702561901952
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
podman wait
podman wait [options] <container>
Waits for the specified container to meet a condition. The default condition is stopped .
Example:
The following example uses podman ps -a to list containers on the local computer. Then the podman wait: command is
issued against the container with the UUID 569ddc895737 . The current process (in this case, the user’s terminal) waits
until the container with the UUID 569ddc895737 stops.
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
a4b59499314f docker.io/library/nginx:latest nginx -g daemon o... 23 hours ago Up About an hour
ago 0.0.0.0:8181->80/tcp mynginx
569ddc895737 quay.io/openzipkin/zipkin:latest 46 minutes ago Up 44 minutes ago
myzipkin
podman stats
podman stats [options] [<container>]
developers.redhat.com redhat-developer @rhdevelopers
Displays a live stream of a container’s resource usage. The container can be specified by name or UUID. If no
container is specified, the command displays a live stream of the statistics for all containers running as root.
Note: The command podman stats must be executed as sudo and shows only containers running with root privileges.
Example:
The following example calls the podman stats command as the root user. Because no container name or: UUID is
defined in the command, podman stats shows the stats for all containers running as root on the local machine:
podman inspect
podman inspect [options] <container>
Returns metadata describing a running container. The container can be specified by name or UUID. The default
format for the metadata is JSON.
Example:
The following example inspects the container with the name myginx . The result is piped to the more command with
the -10 option to display the first 10 lines of output.
The following sections describe the various Podman commands for working with containers and container images
beyond creating, running, and stopping containers.
developers.redhat.com redhat-developer @rhdevelopers
podman ps
podman ps [options]
Example:
The following example uses podman ps -a to show all containers on the local computer, including those that are
running and those in another state such as Created or Exited :
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
a4b59499314f docker.io/library/nginx:latest nginx -g daemon o... 23 hours ago Up 22 minutes
ago 0.0.0.0:8181->80/tcp mynginx
569ddc895737 quay.io/openzipkin/zipkin:latest 38 seconds ago Exited (143) 3
seconds ago myzipkin
podman commit
podman commit [options] <container> <new_image>:<tag>
Creates a new container image based on the current state of a running container. The container can be specified by
name or UUID.
Example:
The following example creates a new container image named yourzipkin with the tag test from the running container
named myzipkin .
Then podman images lists the container images on the computer. Note that the container image localhost/yourzipkin:test
is listed:
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/yourzipkin test 179d9b389a21 21 seconds ago 156
MB
localhost/mynode v1 a6b028f25b45 24 hours ago 1.02
GB
podman attach
podman attach [options] <container>
Attaches to a running container and views its output or controls it. The container can be specified by name or UUID.
Use the key sequence Ctrl + p Ctrl + q to detach from the container while leaving it running.
developers.redhat.com redhat-developer @rhdevelopers
Example:
podman exec
podman exec <container> <command>
Executes a command in a running container. The container can be specified by name or UUID.
Example:
podman top
podman top <container>
Displays the running processes of a container. The container can be specified by name or UUID.
Example:
The following example displays the processes running within the container named myginx , along with their CPU
utilization:
podman logs
podman logs [options] <container>
Displays the logs of a container. The container can be specified by name or UUID.
developers.redhat.com redhat-developer @rhdevelopers
Example:
The following example uses the command podman logs to display log information about the container named myginx .
The -t option displays the timestamp for each log entry:
podman pause
podman pause [options] [<container>]
Pauses all the processes in a specified container or all containers. The command can be run only against containers
that have root privileges. The container can be specified by name or UUID.
Example:
The following example pauses the container named rootnginx . The command is run using the sudo command
because the container named rootnginx has root privileges:
podman unpause
podman unpause [options] [<container>]
developers.redhat.com redhat-developer @rhdevelopers
Unpauses all processes in a specified container or all containers. The command can be run only against containers
that have root privileges. The container can be specified by name or UUID.
Example:
The following example restarts the container named rootnginx from a paused state. The command is run using the
sudo command because the container named rootnginx has root privileges:
podman port
podman port [options] <container>
Lists the port mappings from a container to localhost. The container can be specified by name or UUID.
Example:
The following example reports the port binding for the container named mynginx :
The sections describe the Podman commands for dealing with the host computer’s file system.
podman diff
podman diff [options] <container>
Displays all the changes caused by a container to the filesystem. The container can be specified by name or UUID.
Example:
The following example reports how the files and directories on the host operating system have been affected by
running the container named mynginx . The letter C indicates the the file or directory has been changed.
: The letter A
indicates that the file or directory has been added:
developers.redhat.com redhat-developer @rhdevelopers
podman mount
podman mount [options] <container>
Mounts and reports the location of a container’s filesystem on the host computer. This command is useful to inspect
the filesystem of a container without having to run podman exec -it to enter the running container. The container can be
specified by name or UUID.
Example:
The following example lists the containers running as root on the local computer. Then the command
sudo podman mount is called on the running container named myredis . The result of calling sudo podman mount
is the directory where the container’s files are located. Finally, sudo ls is called on the container’s directory. Note that
the filesystem has the root directories of a Linux computer running Redis. The command must be run as sudo :
$ sudo podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
f7ac2c719ff7 docker.io/library/redis:latest redis-server 3 days ago Created
myredis
$ sudo ls /var/lib/containers/storage/overlay/
b4f1aaed89bc56ab7b6b63fc6124623036497619cc9f7392bfb529bf1f38ba45/merged
bin boot data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp
usr var
podman umount
podman umount [options] <container>
Unmounts a container’s root filesystem. The container can be specified by name or UUID.
developers.redhat.com redhat-developer @rhdevelopers
Example:
The following command unmounts a container named myredis . The command must be run as sudo :
podman export
podman export -o <output_filename> <container>
Exports a container’s filesystem to a tar file (a compressed package containing a complete directory structure). The
container can be specified by name or UUID.
Example:
The following example uses the command podman ps -a to list the containers running on the local computer. Then the
podman export command exports the filesystem of the container named mynginx to a tar file named mynginx.tar .
Finally, the command ls - lh describes the details of the tar file:
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
a4b59499314f docker.io/library/nginx:latest nginx -g daemon o... 3 days ago Up 50 minutes ago
0.0.0.0:8181->80/tcp mynginx
$ ls -lh
total 138M
-rw-rw-r--. 1 guest guest 138M Feb 28 09:44 mynginx.tar
podman import
podman import <tar_filename>
Example:
The following example creates a container image from an existing tar file named mynginx.tar . The command creates a
new-nginx with the tag v1 . Finally, the command podman images is called to list the container image that was created:
developers.redhat.com redhat-developer @rhdevelopers
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/new-nginx v1 ad3620ffa74c 41 minutes ago 144 MB
Miscellaneous
The following sections describe commands for discovering version and other information about Podman.
podman version
podman version
Example:
The following example shows information about the installed version of Podman:
$ podman version
Version: 3.4.2
API Version: 3.4.2
Go Version: go1.16.7
Built: Thu Jan 13 02:15:49 2022
OS/Arch: linux/amd64
podman info
podman info
Displays information about the instance of Podman installed on the local computer.
Example:
The following example displays information about the instance of Podman installed on the local computer. The
output is piped to the more command using the -10 option to show the first 10 lines of output:
developers.redhat.com redhat-developer @rhdevelopers