Pages

Monday, August 8, 2022

PodMan

Podman is container runtime engine like docker, Rocket, Drawbridge, LXC. 


podman login -u username -p password registry.access.redhat.com
podman pull [OPTIONS] [REGISTRY[:PORT]/]NAME[:TAG]

podman ps -a
podman search <image-name>
podman pull <image-name>
podman images
podman run <image-name> echo 'Hello world!'
podman run -d -p 8080 httpd << Run a container with image httpd in background with -d
podman port -l <<  Displays port details of last used container
podman run -it ubi8/ubi:8.3 /bin/bash << Run and enter to bash of a container with -it
podman run --name MySQL-custom \ 
    -e MYSQL_USER=Ruser -e MYSQL_PASSWORD=PASS \
    -e MYSQL_ROOT_PASSWORD= PASS \
    -d MySQL
podman ps --format "{{.ID}} {{.Image}} {{.Names}}"

 

Root and Rootless Containers

sudo podman run --rm --name asroot -ti httpd /bin/bash
podman run --rm --name asuser -ti httpd /bin/bash

podman run --name my-httpd-container httpd << Custom name to pod with --name
podman exec httpd-container cat /etc/hostname << Running commands in container with exec
podman stop my-httpd-container
podman kill -s SIGKILL my-httpd-container << send custom kill signals by -s
podman restart my-httpd-container
podman rm my-httpd-container


podman rm -a << Remove all pods
podman stop -a << Stop all pods


podman exec mysql /bin/bash -c 'mysql -uuser1 -pmypa55 -e "select * from items.Projects;"'
Sharing a local directory to container. 

First setup the local directory with proper selinux permission
mkdir /home/student/dbfiles
podman unshare chown -R 27:27 /home/student/dbfiles << 
sudo semanage fcontext -a -t container_file_t '/home/student/dbfiles(/.*)?'
sudo restorecon -Rv /home/student/dbfiles
ls -ldZ /home/student/dbfiles 

The mount the path with -v location_in_local:location_in_container 
podman run -v /home/student/dbfiles:/var/lib/mysql rhmap47/mysql
podman unshare chown 27:27 /home/student/local/mysql

 Port management


podman run -d --name apache1 -p 8080:8080 httpd
podman run -d --name apache2 -p 127.0.0.1:8081:8080 httpd
podman run -d --name apache3 -p 127.0.0.1::8080 httpd
podman port apache3

Podman Image Management
Podman is available on a RHEL host with the following entry in /etc/containers/ registries.conf file: 

[registries.search] 
registries = ["registry.redhat.io","quay.io"]

podman save [-o FILE_NAME] IMAGE_NAME[:TAG]
podman save -o mysql.tar quay.io/mysql:latest

podman load [-i FILE_NAME]
podman load -i mysql.tar

podman rmi [OPTIONS] IMAGE [IMAGE...]
podman rmi -a

podman commit [OPTIONS] CONTAINER [REPOSITORY[:PORT]/]IMAGE_NAME[:TAG]
podman commit mysql-basic mysql-custom
podman commit -a 'Your Name' httpd httpd-new


podman diff container-name << diff subcommand tags any added file with an A, any changed ones with a C, and any deleted file with a D.

podman tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
podman tag mysql-custom devops/mysql


podman rmi devops/mysql:snapshot

podman push [OPTIONS] IMAGE [DESTINATION]
podman push quay.io/bitnami/nginx










No comments:

Post a Comment