Podman Cheatsheet

Podman Cheatsheet

Publish Date: Feb 3
1 0

Images

Listing Images

podman images
Enter fullscreen mode Exit fullscreen mode

Pulling an Image

podman pull jenkins
Enter fullscreen mode Exit fullscreen mode

Deleting Images

podman rmi <image-name or image-id>
Enter fullscreen mode Exit fullscreen mode

Remove un-used images at once

podman image prune
Enter fullscreen mode Exit fullscreen mode
podman rmi $(podman images -aq)
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

Saving images to your local in archive

podman image save -o image.tar <image-id>
Enter fullscreen mode Exit fullscreen mode

Load a container from a stored archive

podman load -i archive_name.tar
Enter fullscreen mode Exit fullscreen mode

Tagging an image

podman tag <image-id> target-image-name

# Tagging images with a tag
podman tag -t <image-id> target-image-name:tag
Enter fullscreen mode Exit fullscreen mode

Containers

Listing the containers that are running.

podman ps
Enter fullscreen mode Exit fullscreen mode

Listing all containers in your machine

podman ps -a
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

Stopping a container

podman stop <container-id>
Enter fullscreen mode Exit fullscreen mode

Starting a stopped container

podman start <container-id>
Enter fullscreen mode Exit fullscreen mode

Removing a container

podman rm <container-id>
Enter fullscreen mode Exit fullscreen mode

Logs of a container

podman logs <container-id>

# Watching logs 
podman logs --tail=100 -f <container-id>
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Creating an image from a container

podaman commit <container-ID> image_name
Enter fullscreen mode Exit fullscreen mode

Inspecting a container

podman inspect <container-id>
Enter fullscreen mode Exit fullscreen mode

Network

Listing Networks

podman network ls
Enter fullscreen mode Exit fullscreen mode

Creating a network

podman network create net-1
Enter fullscreen mode Exit fullscreen mode

Removing a network

podman network rm net-1
Enter fullscreen mode Exit fullscreen mode

Attaching network to a container

podman network connect <container-id>
Enter fullscreen mode Exit fullscreen mode

Attaching network at while running the container

podman run -d --network net-1 --name jenkins <image-id>
Enter fullscreen mode Exit fullscreen mode

Inspecting a network

podman network inspect net-1
Enter fullscreen mode Exit fullscreen mode

Volumes

Creating a volume

podman volume create volume-1
Enter fullscreen mode Exit fullscreen mode

Listing Volumes

podman volume ls
Enter fullscreen mode Exit fullscreen mode

Removing Volumes

podman volume rm volume-1
Enter fullscreen mode Exit fullscreen mode

Removing unused volumes in your machine

podman volume prune
Enter fullscreen mode Exit fullscreen mode

Attaching Volume while running the container

podman run -d --volume volume-1:/var/jenkins_home --network net-1 --name jenkins <image-id>
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment