Podman Flashcards
Search for images containing button
podman search button
Download images containing button
podman pull button
List local images
podman images
Run container ubi8/ubi:8.3 such that it prints ‘Hello word’
podman run ubi8/ubi:8.3 echo ‘Hello world!’
Explain the -d option
Run container image as a background process
Run bash on container ubi8/ubi:8.3
podman run -it ubi8/ubi:8.3 /bin/bash
Run MySQL with image: registry.redhat.io/rhel8/mysql-80
podman run –name mysql-custom \
> -e MYSQL_USER=redhat -e MYSQL_PASSWORD=r3dh4t \
> -e MYSQL_ROOT_PASSWORD=r3dh4t \
> -d registry.redhat.io/rhel8/mysql-80
Run container to set environment variable GREET and print it
podman run -e GREET=Hello -e NAME=RedHat \
> ubi8/ubi:8.3 printenv GREET NAME
Run bash on a running container
podman exec -it mysql-basic /bin/bash
Displays all actively running containers
podman ps
Displays all running and stopped containers
podman ps -a
Stop container my-httpd-container
podman stop my-httpd-container
Kill container
podman kill my-httpd-container
Restart container
podman restart my-httpd-container
Remove container
podman rm my-httpd-container
Restart container
podman restart my-httpd-container
Delete all containers
podman rm -a
Stop all containers
podman stop -a
Login to container registry
podman login registry.redhat.io
View container logs
podman logs mysql-db
Copy database file to mysql container.
podman cp ~/db.sql mysql:/
Execute sql query inplace in mysql container
podman exec mysql /bin/bash -c ‘mysql -uuser1 -pmypa55 -e “select * from items.Projects;”’
Explain podman unshare
provides a session to execute commands within the same user namespace as the process running inside the container
Example unshare command
podman unshare chown -R 27:27 /home/student/dbfiles
mount a host directory to a container,
podman run -v /home/student/dbfiles:/var/lib/mysql rhmap47/mysql
List a container’s ports
podman port apache3
Where do to you configure registries use by podman?
/etc/containers/registries.conf
What is the format of image files when stored locally?
.tar
Syntax of the save command
podman save [-o FILE_NAME] IMAGE_NAME[:TAG]
How do you use container stored locally?
podman load -i mysql.tar
Delete image from local storage
podman rmi [OPTIONS] IMAGE [IMAGE…]
Delete all images that are not used by any container
podman rmi -a
Save container from registry
podman save -o mysql.tar registry.redhat.io/rhel8/mysql-80
Turn running container into new image
podman commit mysql-basic mysql-custom
Tag an image as latest
podman tag 0e3bbc2 fedora:latest
podman tag httpd myregistryhost:5000/fedora/httpd:v2
Tag a new image as snapshot
podman tag mysql-custom devops/mysql:snapshot
Untag an image
podman rmi devops/mysql:snapshot
Push image to registry
podman push quay.io/bitnami/nginx
podman diff official-httpd
examine the differences in the container between the image and the new layer created by the container.
Inspect changes on a container or image’s filesystem.
podman diff official-httpd
Mysql image
rhel8/mysql-80
Base image
ubi8/ubi:8.5
List of all running containers in json
podman ps –all –format=json
Create a network
podman network create
List existing networks
podman network ls
Outputs a detailed JSON object containing configuration data for the network.
podman network inspect
Delete network
podman network rm
Removes any networks that are not currently in use by any running containers
podman network prune
Connects an already running container to or from an existing network.
podman network connect
disconnects a container from a network
podman network disconnect
creates a new container called my-container, which is connected to the example-net network
podman run -d –name my-container \
–net example-net container-image:latest
creates a new container called double-connector that connects to both the postgres-net and redis-net networks
podman run -d –name double-connector \
–net postgres-net,redis-net \
container-image:latest
connect existing container to the example-net network
podman network connect example-net my-container
When using the default network, the domain name system (DNS) is disabled. True or False.
True
To use DNS, create a new Podman network and connect your containers to that network
get private IP of container
podman inspect my-app \
-f ‘{{.NetworkSettings.Networks.apps.IPAddress}}’
Start process cat in running container called httpd
podman exec httpd cat /etc/httpd/conf/httpd.conf
find whether the container is running
podman inspect –format=’{{.State.Status}}’ httpd
ubi image
ubi8/ubi:8.6
python image
ubi8/python-39:latest
nodejs image
ubi8/nodejs-16:1
GO image
ubi8/go-toolset
How to inspect remote image
use skopeo
List servers of all images on your machine
podman image ls –format “{{.Repository}}”
Inspect image to see which command it runs by default
podman image inspect simple-server \
–format=”{{.Config.Cmd}}”
inspect the image layers
podman image tree ubi-httpd
difference between volumes and binds
Volumes are data mounts managed by Podman. Bind mounts are data mounts managed by the user.
attach volume using mount
–mount type=TYPE,source=/path/on/host,destination=/path/in/container
values of type when using mount
bind for bind mounts.
volume for volume mounts.
tmpfs for creating memory-only, ephemeral mounts.
create a new volume called http-data
podman volume create http-data
Determine where a bind volume was mounted
podman volume inspect http-data
Where does podman store bind volumes
$HOME/.local/share/containers/storage/volumes/
Create a bind volume and mount it
1) podman volume create http-data
2) podman run -p 8080:8080 –volume http-data:/var/www/html \
registry.access.redhat.com/ubi8/httpd-24:latest
import data from a tar archive into an existing Podman volume
podman volume import http_data web_data.tar.gz
export data from an existing Podman volume and save it as a tar archive
podman volume export http_data –output web_data.tar.gz
Run postgres so that it stores data on an ephemeral loacation
podman run -e POSTGRESQL_ADMIN_PASSWORD=redhat
–mount type=tmpfs,tmpfs-size=512M,destination=/var/lib/pgsql/data \
registry.redhat.io/rhel9/postgresql-13:1
When would you use tmpfs
for performance
Import data into postgres inside a container
podman exec -it DATABASE_CONTAINER \
psql -U DATABASE_USER -d DATABASE_NAME \
-f CONTAINER_PATH/SQL_FILE
creates an ephemeral container to load data into a PostgreSQL database:
podman run -it –rm \
-e PGPASSWORD=DATABASE_PASSWORD \
-v ./SQL_FILE:/tmp/SQL_FILE:Z \
–network DATABASE_NETWORK \
registry.redhat.io/rhel8/postgresql-12:1-113 \
psql -U DATABASE_USER -h DATABASE_CONTAINER \
-d DATABASE_NAME -f /tmp/SQL_FILE
export the database called DATABASE to a BACKUP_DUMP
podman exec POSTGRESQL_CONTAINER \
pg_dump -Fc DATABASE -f BACKUP_DUMP
Explain the Z option in podman run volume command
Sets SELinux context for the container to have access to the host SQL_FILE.
run the psql client in the same PostgreSQL container
podman exec -it persisting-pg12 \
psql -d rpi-store -c “select * from model”
pant
-p: display the process using the socket
-a: display listening and established connections
-n: display IP addresses
-t: display TCP sockets
get the container PID
podman inspect CONTAINER –format ‘{{.State.Pid}}’
Execute a process in running container with a specific env variable
podman exec -e ENVIRONMENT=dev
reload nginx
podman exec nginx nginx -s reload
nginx config location
/etc/nginx/nginx.conf
restart nginx container
podman restart nginx
remove all containers, including running ones
podman rm –all –force
Create podman link
ln -s /bin/podman pm
PATH=$PATH:.
block pulling images from docker.io
Add this in /etc/containers/registeries.conf
location=”docker.io”
blocked=true
Location of podman credentials after login
${XDG_RUNTIME_DIR}/containers/auth.json
Decode content of auth.json
echo ZGV2ZWxvcGVyOmRldmVsb3Blcg== | base64 -d
Alternative to podman images
podman image ls
build an image with specific tag
podman build –file dir/Dockerfile –tag quay.io/open-sudo/argocd:4.5