Introduction
Currently, I am studying for the EX180 exam. The EX180 exam tests your skills and knowledge of the fundamentals of containers and Openshift, including finding, customizing, running, and managing containerized services. The exam is based on podman and also includes topics on S2I, templates, routes, and more.
Check out the complete exam objectives at: https://www.redhat.com/en/services/training/ex180-red-hat-certified-specialist-containers-kubernetes-exam?section=Objectives
Podman Commands
Here are some commands I have been using to create and manage containers hile studying for the EX180 exam.
-
Logging into a container registry
SYNTAX
podman login REGISTRY_NAME
EXAMPLE
[fritzie@home ~] $ podman login quay.io
-
Searching for container images
SYNTAX
podman search IMAGE_NAME
EXAMPLE
[fritzie@home ~] $ podman search httpd
NAME DESCRIPTION
registry.access.redhat.com/ubi9/httpd-24 rhcc_registry.access.redhat.com_ubi9/httpd-2…
registry.access.redhat.com/rhmap45/httpd Provides an extension to the RHSCL Httpd ima…
registry.access.redhat.com/rhscl/varnish-4-rhel7 Varnish 4 high-performance HTTP accelerator
-
Downloading a container image and saving it locally
SYNTAX
podman pull IMAGE_NAME
EXAMPLE
[fritzie@home ~] $ podman pull httpd
podman pull httpd
✔ docker.io/library/httpd:latest
Trying to pull docker.io/library/httpd:latest…
Getting image source signatures
Copying blob 6b29c2b62286 done
Copying blob 7a6db449b51b done
Copying blob b4effd428409 done
Copying blob 152876b0d24a done
Copying blob c2123effa3fc done
Copying config a981c89925 done
Writing manifest to image destination
Storing signatures
a981c8992512d65c9b450a9ecabb1cb9d35bb6b03f3640f86471032d5800d825
-
Listing locally stored images
SYNTAX
podman images
EXAMPLE
[fritzie@home ~] $ podman images
podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/httpd latest a981c8992512 5 days ago 149 MB
-
Running a container locally based on an image
SYNTAX
podman run IMAGE_NAME ENTRY_POINT
EXAMPLE
[fritzie@home ~] $ podman run httpd echo ‘Hello World!’
Hello World!
NOTE: The entry point is the containeriezed process that the container image runs when it starts.
-
Running a container image as a background process – use the -d (detach) option and -p (specify port)
SYNTAX
podman run -d -p PORT MAGE_NAME
EXAMPLE
[fritzie@home ~] $ podman run -d -p 8282 httpd
[fritzie@home ~] $ podman port -l
8282/tcp -> 0.0.0.0:41069
[fritzie@home ~] curl http://localhost:41069
-
Downloading an image and starting Bash inside the container to run commands interactively -t (start a pseudo-terminal) -i (standard input open in the container)
SYNTAX
podman run -it IMAGE_NAME COMMAND
EXAMPLE
[fritzie@home ~] $ podman run -it ubi8/ubi:8.4 /bin/bash
Resolved “ubi8/ubi” as an alias (/etc/containers/registries.conf.d/001-rhel-shortnames.conf)
Trying to pull registry.access.redhat.com/ubi8/ubi:8.4…
Getting image source signatures
Checking if image destination supports signatures
Copying blob eac1b95df832 done
Copying blob 47aa3ed2034c done
Copying config b1e63aaae5 done
Writing manifest to image destination
Storing signatures
Inserting environment variables into a container at startup using -e
SYNTAX
podman run -e ENV1=ENV1 -e ENV2=ENV2 IMAGE_NAME COMMAND
EXAMPLE
[fritzie@home ~] $ podman run -it -e GREETING=”Good Evening!” -e NAME=Jamie ubi8\ubi:8.4 /bin/bash
[root@2374f0cda99e /]# echo $GREETING $NAME
Good Evening! Jamie
-
Starting a container in the background (-d) and mapping port 8888 on the host to port 80 in the container and testing that the apache server is running inside the my-httpd container
SYNTAX
podman run -d -p HOST_PORT:CONTAINER_PORT –name CONTAINER_NAME IMAGE
EXAMPLE
[fritzie@home ~] $ podman run -d -p 8888:80 –name my-httpd docker.io/library/httpd:latest
078e216b790de0952aa92574ba4fb8d6ee47ae5a449996a34eaf6e5fdbd1f011
[fritzie@home ~] $ curl http://localhost:8888
<html><body><h1>It works!</h1></body></html>
-
Listing all running containers
SYNTAX
podman ps
EXAMPLE
[fritzie@home ~] $ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
078e216b790d docker.io/library/httpd:latest httpd-foreground 4 minutes ago Up 4 minutes ago 0.0.0.0:8888->80/tcp my-httpd
-
Running a command inside a running container
SYNTAX
podman exec CONTAINER_ID or CONTAINER_NAME COMMAND
EXAMPLE
[fritzie@home ~] $ podman exec my-httpd ls -l /var/log
total 136
-rw-r–r–. 1 root root 3632 Aug 23 03:32 alternatives.log
drwxr-xr-x. 2 root root 60 Aug 23 03:32 apt
-rw-rw—-. 1 root utmp 0 Aug 22 00:00 btmp
-rw-r–r–. 1 root root 94940 Aug 23 03:32 dpkg.log
-rw-r–r–. 1 root root 3232 Aug 22 00:00 faillog
-rw-rw-r–. 1 root utmp 29492 Aug 22 00:00 lastlog
-rw-rw-r–. 1 root utmp 0 Aug 22 00:00 wtmp
-
Stopping a container
SYNTAX
podman stop CONTAINER_ID or CONTAINER_NAME
EXAMPLE
[fritzie@home ~] $ podman stop my-httpd
my-httpd
[fritzie@home ~] $ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-
Restarting a stopped container
SYNTAX
podman restart CONTAINER_ID or CONTAINER_NAME
EXAMPLE
[fritzie@home ~] $ podman restart 078e216b790d
078e216b790de0952aa92574ba4fb8d6ee47ae5a449996a34eaf6e5fdbd1f011
[fritzie@home ~] $ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
078e216b790d docker.io/library/httpd:latest httpd-foreground 14 minutes ago Up 3 seconds ago 0.0.0.0:8888->80/tcp my-httpd