[student@servera ~]$ podman login -u admin -p redhat321 utility.lab.example.com Error: authenticating creds for"utility.lab.example.com": pinging container registry utility.lab.example.com: Get "https://utility.lab.example.com/v2/": tls: failed to verify certificate: x509: certificate is not valid for any names, but wanted to match utility.lab.example.com
[student@servera ~]$ podman login --help Description: Log in to a container registry on a specified server. Usage: podman login [options] [REGISTRY] Examples: podman login quay.io podman login --username ... --password ... quay.io podman login --authfile dir/auth.json quay.io Options: --authfile string path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override --cert-dir string use certificates at the specified path to access the registry --get-login Return the current login user for the registry -p, --password string Password for registry --password-stdin Take the password from stdin --tls-verify Require HTTPS and verify certificates when contacting registries -u, --username string Username for registry -v, --verbose Write more detailed information to stdout
# 列出本地存储中的镜像 [student@servera ~]$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE utility.lab.example.com/ubi7/ubi latest 87dd8ec61bbc 4 years ago 215 MB utility.lab.example.com/rhel8/mariadb-103 latest 11a47e0fbed0 4 years ago 572 MB
# 镜像信息注解: REPOSITORY :仓库地址 TAG :标记,latest最近版本 IMAGE ID :镜像ID,ID号唯一,保证镜像唯一性 CREATED :创建时间; SIZE :镜像大小
podman run -t 终端 -i 交互 -d 放在后台 --name 指定容器的名称,如果不指定,会自从产生名称
[student@servera ~]$ podman run -it utility.lab.example.com/ubi7/ubi [student@servera ~]$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 537b1f1fbb6d utility.lab.example.com/ubi7/ubi:latest /bin/bash About a minute ago Up About a minute objective_antonelli
#实验前可以提前下载镜像至本地 #podman search utility.lab.example.com/ #podman pull utility.lab.example.com/ubi8/ubi #podman images [student@servera ~]$ podman run -it --name rhel9 utility.lab.example.com/ubi9/ubi [student@servera ~]$ podman run -di --name rhel9-1 utility.lab.example.com/ubi9/ubi [student@servera ~]$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 537b1f1fbb6d utility.lab.example.com/ubi7/ubi:latest /bin/bash 5 minutes ago Up 5 minutes objective_antonelli fb45a06e2271 utility.lab.example.com/ubi9/ubi:latest /bin/bash 56 seconds ago Up 57 seconds rhel9-1
# ctrl+d退出后再查看容器的状态 [student@servera ~]$ podman exec -ti rhel9-1 /bin/bash [student@servera ~]$ podman run -d --name rhel9-2 utility.lab.example.com/ubi9/ubi sleep infinity [student@servera ~]$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb45a06e2271 utility.lab.example.com/ubi9/ubi:latest /bin/bash 5 minutes ago Up 5 minutes rhel9-1 c4f7f4d72747 utility.lab.example.com/ubi9/ubi:latest sleep infinity 34 seconds ago Up 34 seconds rhel9-2
[student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 850618efbece utility.lab.example.com/ubi9/ubi:latest /bin/bash 10 hours ago Exited (0) 10 hours ago rhel9 fb45a06e2271 utility.lab.example.com/ubi9/ubi:latest /bin/bash 10 hours ago Up 10 hours rhel9-1 c4f7f4d72747 utility.lab.example.com/ubi9/ubi:latest sleep infinity 10 hours ago Up 10 hours rhel9-2 f4c3d26df7bd utility.lab.example.com/rhel8/mariadb-103:latest run-mysqld About an hour ago Exited (1) About an hour ago python36-db 8e7870d50daa utility.lab.example.com/ubi9/ubi:latest /bin/bash 55 minutes ago Up 55 minutes python38 2d4b030f4141 utility.lab.example.com/ubi7/ubi:latest /bin/bash 39 minutes ago Up 39 minutes rhel7 student@servera ~]$ podman rmi utility.lab.example.com/ubi9/ubi:latest Error: image used by 8e7870d50daa32c768c4301911364285a659a5383b4cdadc96b8d3b7ff411c2d: image is in use by a container: consider listing external containers and force-removing image
[student@servera ~]$ podman rm --help [student@servera ~]$ podman rm python38 python38 [student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 850618efbece utility.lab.example.com/ubi9/ubi:latest /bin/bash 10 hours ago Exited (0) 10 hours ago rhel9 fb45a06e2271 utility.lab.example.com/ubi9/ubi:latest /bin/bash 10 hours ago Up 10 hours rhel9-1 c4f7f4d72747 utility.lab.example.com/ubi9/ubi:latest sleep infinity 10 hours ago Up 10 hours rhel9-2 f4c3d26df7bd utility.lab.example.com/rhel8/mariadb-103:latest run-mysqld About an hour ago Exited (1) About an hour ago python36-db 2d4b030f4141 utility.lab.example.com/ubi7/ubi:latest /bin/bash 45 minutes ago Up 45 minutes rhel7
** 当容器不再存在时,可以使用podman rmi命令删除对应的镜像:**
1 2 3 4 5 6 7 8 9 10 11 12 13
[student@servera ~]$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/rhel7 2.0 98d0b6385a00 11 hours ago 238 MB utility.lab.example.com/ubi9/ubi latest 8d2a8803cfca 12 months ago 219 MB utility.lab.example.com/ubi7/ubi latest 87dd8ec61bbc 4 years ago 215 MB utility.lab.example.com/rhel8/mariadb-103 latest 11a47e0fbed0 4 years ago 572 MB [student@servera ~]$ podman rmi 8d2a8803cfca Error: image used by c4f7f4d727471d590f6241cccf0be0b1ef2256cc43a710594642611fe6d0be47: image is in use by a container: consider listing external containers and force-removing image [student@servera ~]$ podman rmi 98d0b6385a00 Untagged: localhost/rhel7:2.0 Deleted: 98d0b6385a005e09cfcee59a393cfce2fc46b56f09af6c4f87bd874f00966ed2 Deleted: 53c739e51f226903b6568038c9cf563de2007f756e0a0e86e5c00604cf474f3d Deleted: 92b83aa1157f23b209f53480c6bbdf780c39490b37337bc4f4fcb1061b7c978
[student@servera ~]$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE utility.lab.example.com/ubi9/ubi latest 8d2a8803cfca 12 months ago 219 MB utility.lab.example.com/ubi7/ubi latest 87dd8ec61bbc 4 years ago 215 MB utility.lab.example.com/rhel8/mariadb-103 latest 11a47e0fbed0 4 years ago 572 MB [student@servera ~]$ podman run -d --name db01 utility.lab.example.com/rhel8/mariadb-103 29decc6e48d62506e62e503a383943709138a8f789a32dd27d2fa1761bf3ea9f
# 发现容器无法启动 [student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29decc6e48d6 utility.lab.example.com/rhel8/mariadb-103:latest run-mysqld 2 minutes ago Exited (1) 2 minutes ago db01
使用podman container logs命令调查容器状态的原因。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[student@servera ~]$ podman container logs db01 Warning: Can't detect memory limit from cgroups Warning: Can't detect number of CPU cores from cgroups Warning: Can't detect memory limit from cgroups Warning: Can't detect number of CPU cores from cgroups => sourcing 20-validate-variables.sh ... You must either specify the following environment variables: MYSQL_USER (regex: '^[a-zA-Z0-9_]+$') MYSQL_PASSWORD (regex: '^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$') MYSQL_DATABASE (regex: '^[a-zA-Z0-9_]+$') Or the following environment variable: MYSQL_ROOT_PASSWORD (regex: '^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$') Or both. Optional Settings: ......
1 2 3 4 5 6 7 8 9 10 11 12 13
# 输出中的usage 标签提供了如何运行镜像的示例。url标签指向红帽容器目录中的一个Web页面,其中记录了环境变量以及有关如何使用容器镜像的其他信息。 # 此镜像的文档显示容器将3306端口用于数据库服务。文档中还显示了以下环境变量可用于配置数据库服务: [student@servera ~]$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE utility.lab.example.com/ubi9/ubi latest 8d2a8803cfca 12 months ago 219 MB utility.lab.example.com/ubi7/ubi latest 87dd8ec61bbc 4 years ago 215 MB utility.lab.example.com/rhel8/mariadb-103 latest 11a47e0fbed0 4 years ago 572 MB [student@servera ~]$ podman inspect utility.lab.example.com/rhel8/mariadb-103 | grep usage "usage": "podman run -d -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -p 3306:3306 rhel8/mariadb-103", "usage": "podman run -d -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -p 3306:3306 rhel8/mariadb-103",
# 容器启动成功 [student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 41a62ff2efd7 utility.lab.example.com/rhel8/mariadb-103:latest run-mysqld 8 seconds ago Up 8 seconds db01
# db01容器未在运行 [student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 54279d1fff7f utility.lab.example.com/rhel8/mariadb-103:latest run-mysqld 6 minutes ago Exited (1) 6 minutes ago db01
[student@servera ~]$ podman rm -af 54279d1fff7f3b679dd9d4efb7bfa28a626f41f7d07bea50a445ec2392c8cb02 [student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6195fc399b1f utility.lab.example.com/rhel8/mariadb-103:latest run-mysqld 23 seconds ago Up 24 seconds db01
[student@servera ~]$ podman rm -af 6195fc399b1f6ae8f5b9d3f436c02bb5d6b093b597949dc968b2a64f6e7d023c [student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[student@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 28202973f22d utility.lab.example.com/rhel8/mariadb-103:latest run-mysqld 20 seconds ago Up 20 seconds 0.0.0.0:13306->3306/tcp db01
[kiosk@foundation0 ~]$ sudo dnf -y install mariadb [kiosk@foundation0 ~]$ mysql -u user -ppass -h servera -P 13306 # -h 后面填写您当前实验的主机名或IP Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.3.17-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | db | | information_schema | | test | +--------------------+ 3 rows inset (0.012 sec)
MariaDB [(none)]> USE db; Database changed MariaDB [db]> SHOW TABLES; Empty set (0.001 sec)
[student@servera ~]$ sudo useradd appdev-adm [sudo] password for student:student [student@servera ~]$ sudo passwd appdev-adm Changing password for user appdev-adm. New password: BAD PASSWORD: The password is shorter than 8 characters Retype new password: passwd: all authentication tokens updated successfully.
然后,使用 su命令切换到appdev-adm用户,并使用podman命令来启动。
1 2 3 4 5 6 7
[student@servera ~]$ su appdev-adm Password:redhat [appdev-adm@servera student]$ podman info ERRO[0000] XDG_RUNTIME_DIR directory "/run/user/1000" is not owned by the current user [root@servera ~]# su appdev-adm [appdev-adm@servera root]$ podman info ERRO[0000] XDG_RUNTIME_DIR directory "/run/user/0" is not owned by the current user
[appdev-adm@servera root]$ exit exit [root@servera ~]# ssh appdev-adm@localhost appdev-adm@localhost's password: Register this system with Red Hat Insights: insights-client --register Create an account or view all your systems at https://red.ht/insights-dashboard Last login: Tue Mar 4 09:06:27 2025 [appdev-adm@servera ~]$ podman info [appdev-adm@servera ~]$ podman login -u admin -p redhat321 utility.lab.example.com Login Succeeded! [appdev-adm@servera ~]$ podman search utility.lab.example.com/ NAME DESCRIPTION utility.lab.example.com/rhel8/mariadb-103 utility.lab.example.com/rhel9/mariadb-105 utility.lab.example.com/rhel9/httpd-24 utility.lab.example.com/library/nginx utility.lab.example.com/ubi7/ubi utility.lab.example.com/ubi9/ubi utility.lab.example.com/ubi8/ubi utility.lab.example.com/ubi9/python-312 utility.lab.example.com/rhel9/php-82
然后,配置容器注册表并使用您的凭据进行身份验证。您可以使用以下命令运行 http 容器。
1 2 3 4 5 6 7 8 9 10
[appdev-adm@servera ~]$ mkdir /home/appdev-adm/nginx_web/ [appdev-adm@servera ~]$ echo nginx_web_page > /home/appdev-adm/nginx_web/index.html [appdev-adm@servera ~]$ cat /home/appdev-adm/nginx_web/index.html nginx_web_page [appdev-adm@servera ~]$ podman run -d --name nginx -v /home/appdev-adm/nginx_web/:/usr/share/nginx/html/:Z -p 8080:80 utility.lab.example.com/library/nginx [appdev-adm@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6f72fe3fc6d7 utility.lab.example.com/library/nginx:latest nginx -g daemon o... 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp nginx [appdev-adm@servera ~]$ curl localhost:8080 nginx_web_page
# 重启后进行测试 [kiosk@foundation0 ~]$ ssh root@servera [root@servera ~]# ssh appdev-adm@localhost [appdev-adm@servera ~]$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6f72fe3fc6d7 utility.lab.example.com/library/nginx:latest nginx -g daemon o... 40 minutes ago Up About a minute 0.0.0.0:8080->80/tcp nginx