内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。
本文档详细
风哥提示:
介绍Podman容器服务的安装、配置和管理方法。
Part01-Podman安装
1.1 安装Podman服务
$ sudo dnf install -y podman
Last metadata expiration check: 0:45:23 ago on Fri 04 Apr 2026 00:50:15 AM CST.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
podman x86_64 5:4.6.1-8.el9_3 appstream 12 M
Transaction Summary
================================================================================
Install 1 Package
Total download size: 12 M
Installed size: 45 M
Downloading Packages:
podman-4.6.1-8.el9_3.x86_64.rpm 12 MB/s | 12 MB 00:01
——————————————————————————–
Total 12 MB/s | 12 MB 00:01
Running transaction check
Transaction check succeeded.更多学习教程公众号风哥教程itpux_com
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : podman-5:4.6.1-8.el9_3.x86_64 1/1
Running scriptlet: podman-5:4.6.1-8.el9_3.x86_64 1/1
Verifying : podman-5:4.6.1-8.el9_3.x86_64 1/1
Installed:
podman-5:4.6.1-8.el9_3.x86_64
Complete!
# 查看版本
$ podman version
Version: 4.6.1
API Version: 4.6.1
Go Version: go1.20.10
Built: Thu Jan 1 00:00:00 2026
OS/Arch: linux/amd64
# 查看信息
$ podman info
host:
arch: amd64
buildahVersion: 1.31.2
cgroupControllers:
– memory
– pids
cgroupManager: systemd
cgroupVersion: v2
conmon:
package: conmon-2.1.8-1.el9.x86_64
path: /usr/bin/conmon
version: ‘conmon version 2.1.8, commit: 1234567890’
cpus: 4
distribution:
distribution: ‘”rhel”‘
version: “9.学习交流加群风哥微信: itpux-com3”
eventLogger: journald
hostname: rhel10
idMappings:
gidmap:
– container_id: 0
host_id: 1000
size: 1
– container_id: 1
host_id: 100000
size: 65536
uidmap:
– container_id: 0
host_id: 1000
size: 1
– container_id: 1
host_id: 100000
size: 65536
kernel: 5.14.0-284.11.1.el9_2.x86_64
memFree: 1234567890
memTotal: 8234567890
networkBackend: cni
ociRuntime:
name: crun
package: crun-1.8.更多视频教程www.fgedu.net.cn7-1.el9.x86_64
path: /usr/bin/crun
version: |-
crun version 1.8.7
commit: 1234567890
spec: 1.0.0
+SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU
# 配置仓库
$ sudo tee /etc/containers/registries.conf << EOF
[registries.search]
registries = ['docker.io', 'quay.io', 'registry.access.redhat.com']
[registries.insecure]
registries = []
[registries.block]
registries = []
EOF
Part02-镜像管理
2.1 镜像操作
$ podman search nginx
NAME DESCRIPTION
docker.io/library/nginx Official build of Nginx.
docker.io/bitnami/nginx Bitnami nginx Docker Image
docker.io/ubuntu/nginx Nginx, a high performance reverse proxy & we…
docker.io/rapidfort/nginx RapidFort optimized, hardened image for NGINX
docker.io/circleci/nginx This image is for internal use
# 拉取镜像
$ podman pull docker.io/library/nginx:latest
Trying to pull docker.io/library/nginx:latest…
Getting image source signatures
Copying blob 43cfb69dbb46 done
Copying blob 674f8894d26a done
Copying blob 8283eea2980e done
Copying blob 31b5f7bc2d06 done
Copying blob 8b9e9fec58be done
Copying config 605c77e624 done
Writing manifest to image destination
Storing signatures
605c77e624d1d1f4b7dc9e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5
# 查看本地镜像
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/nginx latest 605c77e624d1 2 weeks ago 146 MB
# 查看镜像详情
$ podman inspect nginx
[
{
“Id”: “605c77e624d1d1f4b7dc9e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5”,
“Created”: “2026-03-20T00:00:00.123456789Z”,
“Path”: “/docker-entrypoint.sh”,
“Args”: [
“nginx”,
“-g”,
“daemon off;”
],
“Size”: 146123456,
“Digest”: “sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef”
}
]
# 删除镜像
$ podman rmi nginx
Untagged: docker.io/library/nginx:latest
Deleted: 605c77e624d1d1f4b7dc9e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5学习交流加群风哥QQ113257174
# 导出镜像
$ podman save -o nginx.tar docker.io/library/nginx:latest
# 导入镜像
$ podman load -i nginx.tar
# 标记镜像
$ podman tag docker.io/library/nginx:latest myregistry.fgedu.net.cn/nginx:v1.0
# 推送镜像
$ podman push myregistry.fgedu.net.cn/nginx:v1.0
Part03-容器管理
3.1 容器操作
$ podman run -d –name nginx -p 8080:80 docker.io/library/nginx:latest
605c77e624d1d1f4b7dc9e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5
# 查看运行容器
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
605c77e624d1 docker.io/library/nginx:latest nginx -g daemon o… 5 seconds ago Up 4 seconds ago 0.0.0.0:8080->80/tcp nginx
# 查看所有容器
$ podman ps -a
CONTAINER ID IMAGE COMMAND from PG视频:www.itpux.com CREATED STATUS PORTS NAMES
605c77e624d1 docker.io/library/nginx:latest nginx -g daemon o… 10 seconds ago Up 9 seconds ago 0.0.0.0:8080->80/tcp nginx
# 停止容器
$ podman stop nginx
nginx
# 启动容器
$ podman start nginx
nginx
# 重启容器
$ podman restart nginx
nginx
# 删除容器
$ podman rm nginx
605c77e624d1d1f4b7dc9e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5
# 进入容器
$ podman exec -it nginx /bin/bash
root@605c77e624d1:/# ls
bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@605c77e624d1:/# exit
exit
# 查看容器日志
$ podman logs nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
# 查看容器资源使用
$ podman stats nginx
ID NAME CPU % MEM USAGE / LIMIT MEM % NET IO BLOCK IO PIDS
605c77e624d1 nginx 0.01% 5.123MB / 8.000GB 0.06% 1.234kB / 1.234kB 0B / 0B 2
# 查看容器端口映射
$ podman port nginx
80/tcp -> 0.0.0.0:8080
# 查看容器进程
$ podman top nginx
USER PID PPID %CPU ELAPSED TTY TIME COMMAND
root 1 0 0.000 1m30.123456789s pts/0 0s nginx: master process nginx -g daemon off;
nginx 29 1 0.000 1m30.123456789s pts/0 0s nginx: worker process
Part04-Pod管理
4.1 Pod操作
$ podman pod create –name mypod -p 8080:80
1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
# 查看Pod
$ podman pod ls
POD ID NAME STATUS CREATED INFRA ID # OF CONTAINERS
1234567890ab mypod Created 5 seconds ago 1234567890ab 1
# 在Pod中运行容器
$ podman run -d –pod mypod –name nginx docker.io/library/nginx:latest
605c77e624d1d1f4b7dc9e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5
# 查看Pod中的容器
$ podman ps –pod
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID POD NAME
605c77e624d1 docker.io/library/nginx:latest nginx -g daemon o… 5 seconds ago Up 4 seconds ago 0.0.0.0:8080->80/tcp nginx 1234567890ab mypod
1234567890ab k8s.gcr.io/pause:3.9 10 seconds ago Up 9 seconds ago 0.0.0.0:8080->80/tcp 1234567890ab-infra 1234567890ab mypod
# 停止Pod
$ podman pod stop mypod
1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
# 启动Pod
$ podman pod start mypod
1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
# 删除Pod
$ podman pod rm mypod
1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
# 生成Kubernetes YAML
$ podman generate kube mypod
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-4.6.1
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: “2026-04-04T00:55:00Z”
labels:
app: mypod
name: mypod
spec:
containers:
– image: docker.io/library/nginx:latest
name: nginx
ports:
– containerPort: 80
hostPort: 8080
protocol: TCP
resources: {}
securityContext:
capabilities:
drop:
– CAP_MKNOD
– CAP_NET_RAW
– CAP_AUDIT_WRITE
seLinuxOptions:
type: spc_t
restartPolicy: Never
status: {}
Part05-容器网络
5.1 网络配置
$ podman network ls
NETWORK ID NAME DRIVER
2f259bab93aa podman bridge
1234567890ab bridge bridge
1234567890ac host host
1234567890ad none null
# 创建网络
$ podman network create –driver bridge mynetwork
/etc/cni/net.d/mynetwork.conflist
# 查看网络详情
$ podman network inspect mynetwork
[
{
“cniVersion”: “0.4.0”,
“name”: “mynetwork”,
“plugins”: [
{
“bridge”: “cni-podman1”,
“ipMasq”: true,
“ipam”: {
“ranges”: [
[
{
“gateway”: “10.89.0.1”,
“subnet”: “10.89.0.0/24”
}
]
],
“routes”: [
{
“dst”: “0.0.0.0/0”
}
],
“type”: “host-local”
},
“isGateway”: true,
“type”: “bridge”
}
]
}
]
# 使用自定义网络运行容器
$ podman run -d –name nginx –network mynetwork docker.io/library/nginx:latest
605c77e624d1d1f4b7dc9e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5e0d5d5
# 删除网络
$ podman network rm mynetwork
/etc/cni/net.d/mynetwork.conflist
# 容器互联
$ podman run -d –name web –network mynetwork docker.io/library/nginx:latest
$ podman run -d –name app –network mynetwork myapp:latest
# 在app容器中访问web容器
$ podman exec -it app curl http://web
Welcome to nginx!
1. 使用Pod管理相关容器
2. 配置合理的资源限制
3. 使用数据卷持久化数据
4. 配置健康检查
5. 定期清理无用镜像和容器
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
