Table of contents
Podman a daemon less container engine, emerged as an alternative to Docker. This cheat sheet is a quick reference to Podman commands, these are also similar to Docker commands. So it can be used a quick reference for docker as well.
Images
Listing Images
podman images
Pulling an Image
podman pull jenkins
Deleting Images
podman rmi <image-name or image-id>
Remove un-used images at once
podman image prune
podman rmi $(podman images -aq)
Building images from a Dockerfile
# . represents that the Dockerfile is present in the location where you are running this command.
podman build -t podman-image:1.0 .
Saving images to your local in archive
podman image save -o image.tar <image-id>
Load a container from a stored archive
podman load -i archive_name.tar
Tagging an image
podman tag <image-id> target-image-name
# Tagging images with a tag
podman tag -t <image-id> target-image-name:tag
Containers
Listing the containers that are running.
podman ps
Listing all containers in your machine
podman ps -a
Running a container
# Running a container normally
podman run <image-id>
# Running a container in detached mode
podman run -d <image-id>
# Adding a name
podman run -d --name jenkins <image-id>
Stopping a container
podman stop <container-id>
Starting a stopped container
podman start <container-id>
Removing a container
podman rm <container-id>
Logs of a container
podman logs <container-id>
# Watching logs
podman logs --tail=100 -f <container-id>
Copying files from/to a container
# Copying files to a container
# It is better to copy files from you podman machine to a container rather than from your local.
# podman cp source_path destination_path
podman cp file_path_in_your_podman_machine container_id:path_in_your_container
# Copying files from your container to your podman machine
podman cp container_id:path_in_your_container file_path_in_your_podman_machine
Logging into a container
podman exec -it <container-id> /bin/bash
# Logging in as a root user
podman exec -it --user root <container-id> /bin/bash
Creating an image from a container
podaman commit <container-ID> image_name
Inspecting a container
podman inspect <container-id>
Podman Network Command
Listing Networks
podman network ls
Creating a network
podman network create net-1
Removing a network
podman network rm net-1
Attaching network to a container
podman network connect <container-id>
Attaching network at while starting the container
podman run -d --network net-1 --name jenkins <image-id>
Inspecting a network
podman network inspect net-1
Podman Volumes
Creating a volume
podman volume create volume-1
Listing Volumes
podman volume ls
Removing Volumes
podman volume rm volume-1
Removing unused volumes in your machine
podman volume prune
Attaching Volume while running the container
podman run -d --volume volume-1:/var/jenkins_home --network net-1 --name jenkins <image-id>