Skip to content

Podman Cheat Sheet

Common usage

$ alias docker=podman

$ podman --version                    # Check version

$ sudo podman login -u USER_NAME REGISTRY_URL
                                    # Login to Registry
$ sudo podman login -u USER_NAME \
  -p ${TOKEN} \
  REGISTRY_URL  
                                    # Login with token or password
                                    # eg: in OpenShift, token can retrive as
                                    # $ TOKEN=$(oc whoami -t)

$ podman logout quay.io             # Remove login credentials for registry.redhat.io
$ podman logout --all               # Remove login credentials for all registries

$ podman search REGISTRY_URL/IMAGE_NAME
                                    # search for an image in registry

$ sudo podman run --name test -u 1234 \
  -p 8080:8080 -d s2i-sample-app

$ sudo podman run -d --name TEST \
  quay.io/USER_NAME/IMAGE_NAME:VERSION
                                    # Create a container 

$ podman run --privileged quay.io/podman/stable podman run ubi8 echo hello
                                    # The easiest way to run Podman inside of a container is to use the --privileged flag.

$ sudo podman ps                    # List running containers
$ sudo podman stop CONTAINER_NAME   # STOP running containers
$ sudo podman rm CONTAINER_NAME     # remove running containers

$ sudo podman rmi IMAGE_NAME        # delete container image
$ sudo podman logs CONTAINER_NAME                    
                                    # check logs of running container

$ sudo podman build -t NAME .       # build container image from Dockerfile and spec
$ sudo podman images                # see available images

Advanced usage

## Rootful Podman in rootful Podman with --privileged
podman run --privileged quay.io/podman/stable podman run ubi8 echo hello

## added volume
podman run --privileged -v ./mycontainers:/var/lib/containers quay.io/podman/stable podman run ubi8 echo hello

## Rootless Podman in rootful Podman with --privileged
podman run --user podman --privileged quay.io/podman/stable podman run ubi8 echo hello

## Rootful Podman in rootful Podman without --privileged
podman run --cap-add=sys_admin,mknod --device=/dev/fuse --security-opt label=disable quay.io/podman/stable podman run ubi8-minimal echo hello

## Run podman inside podman and check podman version
$ podman run --privileged \
  quay.io/podman/stable \
  podman version

## Run podman inside podman and using ubi8 image inside.
$ podman run --privileged \
  quay.io/podman/stable \
  podman run ubi8 echo hello

$ podman run -it --privileged \
  docker.io/mysticrenji/podman \
  podman version

$ podman run -it --privileged \
  docker.io/mysticrenji/podman \
  podman run -d docker.io/library/node:12-alpine

$ podman run -it --privileged \
  docker.io/mysticrenji/podman \
  podman version && git version uptime\
  uptime;\
  git version;\
  git clone https://github.com/mysticrenji/podman-experiments.git;\
  cd podman-experiments;\
  podman-compose up -d;\
  podman-compose down
  podman images

Container commands list

CommandMan PageDescription
attachpodman-container-attach(1)Attach to a running container
checkpointpodman-container-checkpoint(1)Checkpoint a container
cleanuppodman-container-cleanup(1)Cleanup network and mount points of a container
commitpodman-container-commit(1)Commit a container into an image
cppodman-container-cp(1)Copy files/folder into and out of containers
createpodman-container-create(1)Create a new container
diffpodman-container-diff(1)Inspect changes in a containers file system
execpodman-container-exec(1)Run a process in a container
existspodman-container-exists(1)Check if a container exists
exportpodman-container-export(1)Export container’s filesystem as a tar archive
initpodman-container-init(1)Init a container
inspectpodman-container-inspect(1)Display detailed information on a container
killpodman-container-kill(1)Send a signal to containers in container
List (ps)podman-container-list(1)List all of the containers
logspodman-container-logs(1)Fetch logs for a container
mountpodman-container-mount(1)Mount a container’s root filesystem
pausepodman-container-pause(1)Pause container
portpodman-container-port(1)List port mappings for a container
prunepodman-container-prune(1)Remove all non running containers
renamepodman-container-rename(1)Rename an existing container
restartpodman-container-restart(1)Restart a container
restorepodman-container-restore(1)Restore a checkpointed container
rmpodman-container-rm(1)Remove a container
runpodman-container-run(1)Run a command in a new container
runlabelpodman-container-runlabel(1)Execute the command described by an image label
startpodman-container-start(1)Start a container
statspodman-container-stats(1)Display statistics for a container
stoppodman-container-stop(1)Stop a container
toppodman-container-top(1)Display running process in container
unmountpodman-container-unmount(1)Unmount a container’s root filesystem
unpausepodman-container-unpause(1)Unpause all the containers in a pod
waitpodman-container-wait(1)Wait for a container to exit

Pod commands list

CommandMan PageDescription
createpodman-pod-create(1)Create a new pod
existspodman-pod-exists(1)Check if a pod exists
inspectpodman-pod-inspect(1)Display detailed information on a pod
killpodman-pod-kill(1)Send a signal to containers in pod
listpodman-pod-list(1)List all of the pods
logspodman-pod-logs(1)Fetch logs for pod with one or more containers
pausepodman-pod-pause(1)Pause all the containers in a pod
prunepodman-pod-prune(1)Remove all stopped pods and their containers
restartpodman-pod-restart(1)Restart a pod
rmpodman-pod-rm(1)Remove one or more pods
statspodman-pod-stats(1)Display statistics for the containers in a pods
startpodman-pod-start(1)Start a pod
stoppodman-pod-stop(1)Stop a pod
toppodman-pod-top(1)Display running process in the pod
unpausepodman-pod-unpause(1)Unpause all the containers in a pod

Podman on MacOS

## Intall podman and qemu
brew install podman qemu
podman machine init
podman machine start

Reference

  • https://podman.io/
  • https://cloudnweb.dev/2019/06/replacing-docker-with-podman-power-of-podman/
  • https://www.redhat.com/sysadmin/podman-inside-kubernetes
  • Podman in Action - The next generation of container engines (Dan Walsh)

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App