一、什么是podman?
Podman 是一个开源项目,可在大多数 Linux 平台上使用并驻留在GitHub 上。Podman 是一个无守护进程的容器引擎,用于在 Linux 系统上开发、管理和运行 Open Container Initiative (OCI) 容器和容器映像。Podman 提供了一个与 Docker 兼容的命令行前端,它可以简单地为 Docker cli 取别名,别名 docker=podman。Podman 还提供了一个套接字激活的 REST API 服务,以允许远程应用程序启动按需容器。这个 REST API 还支持 Docker API,允许 docker-py 和 docker-compose 的用户与 Podman 作为服务进行交互。
Podman 控制下的容器可以由 root 或非特权用户运行。Podman 使用libpod库管理整个容器生态系统,包括 pod、容器、容器镜像和容器卷。Podman 专注于帮助您维护和修改 OCI 容器映像的所有命令和功能,例如拉取和标记。它允许您在生产环境中创建、运行和维护从这些映像创建的容器。
Podman 服务仅运行在 Linux 平台上,但 Podman 远程 REST API 客户端存在于 Mac 和 Windows 平台上,并且可以通过 ssh 与运行在 Linux 机器或 VM 上的 Podman 服务进行通信。
docker是一个容器引擎,podman也是一个容器引擎
podman官方网址
二、podman安装
[root@localhost ~]# yum -y install podman-docker
[root@localhost ~]# which podman
/usr/bin/podman
[root@localhost ~]# which docker
/usr/bin/docker
[root@localhost ~]# ll /usr/bin/docker
-rwxr-xr-x. 1 root root 163 3月 24 2021 /usr/bin/docker
[root@localhost ~]# ll /usr/bin/podman
-rwxr-xr-x. 1 root root 61006400 3月 24 2021 /usr/bin/podman
三、podman的常用命令
3.1 镜像命令
3.1.1 podman images 查看所有本地主机上的镜像
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest ffe9d497c324 6 days ago 1.46 MB
# 解释
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE ID 镜像的id
CREATED 镜像的创建时间
# 可选项
-a, --all # 列出所有的镜像
-q, --quiet # 只显示镜像的id
3.1.2 podman search 搜索镜像
[root@localhost ~]# podman search nginx
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redhat.com registry.access.redhat.com/ubi8/nginx-118 Platform for running nginx 1.18 or building ... 0
redhat.com registry.access.redhat.com/ubi8/nginx-120 Platform for running nginx 1.20 or building ... 0
redhat.com registry.access.redhat.com/rhscl/nginx-18-rhel7 Nginx 1.8 server and a reverse proxy server 0
redhat.com registry.access.redhat.com/rhscl/nginx-112-rhel7 Nginx is a web server and a reverse proxy se... 0
redhat.com registry.access.redhat.com/rhscl/nginx-110-rhel7 Nginx container image that delivers an nginx... 0
redhat.com registry.access.redhat.com/rhscl/nginx-16-rhel7 Nginx 1.6 server and a reverse proxy server 0
redhat.com registry.access.redhat.com/rhscl/nginx-114-rhel7 Nginx is a web server and a reverse proxy se... 0
redhat.com registry.access.redhat.com/ubi7/nginx-118 Platform for running nginx 1.18 or building ... 0
redhat.com registry.access.redhat.com/3scale-amp23/apicast-gateway 3scale's API gateway (APIcast) is an OpenRe... 0
redhat.com registry.access.redhat.com/3scale-amp20/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.com registry.access.redhat.com/rhamp10/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.com registry.access.redhat.com/3scale-amp20-beta/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.com registry.access.redhat.com/3scale-amp25/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.com registry.access.redhat.com/3scale-amp21/apicast-gateway 3scale AMP image used for API gateway 0
redhat.com registry.access.redhat.com/3scale-amp24/apicast-gateway No description 0
redhat.com registry.access.redhat.com/rhmap45/wildcard-proxy RHMAP image that provides mapping and proxy ... 0
redhat.com registry.access.redhat.com/rhmap46/wildcard-proxy RHMAP image that provides mapping and proxy ... 0
redhat.com registry.access.redhat.com/rhmap47/wildcard-proxy RHMAP image that provides mapping and proxy ... 0
redhat.com registry.access.redhat.com/rhmap43/wildcard-proxy RHMAP Docker image that provides mapping and... 0
redhat.com registry.access.redhat.com/rhmap44/wildcard-proxy RHMAP Docker image that provides mapping and... 0
redhat.com registry.access.redhat.com/3scale-amp22/apicast-gateway APIcast API gateway needs connection to the ... 0
redhat.io registry.redhat.io/rhel8/nginx-114 Nginx is a web server and a reverse proxy se... 0
redhat.io registry.redhat.io/rhel8/nginx-118 Platform for running nginx 1.18 or building ... 0
redhat.io registry.redhat.io/ubi8/nginx-120 Platform for running nginx 1.20 or building ... 0
redhat.io registry.redhat.io/rhel8/nginx-116 Platform for running nginx 1.16 or building ... 0
redhat.io registry.redhat.io/ubi8/nginx-118 Platform for running nginx 1.18 or building ... 0
redhat.io registry.redhat.io/rhel8/nginx-120 Platform for running nginx 1.20 or building ... 0
redhat.io registry.redhat.io/rhscl/nginx-18-rhel7 Nginx 1.8 server and a reverse proxy server 0
redhat.io registry.redhat.io/rhscl/nginx-112-rhel7 Nginx is a web server and a reverse proxy se... 0
redhat.io registry.redhat.io/rhscl/nginx-110-rhel7 Nginx container image that delivers an nginx... 0
redhat.io registry.redhat.io/rhscl/nginx-16-rhel7 Nginx 1.6 server and a reverse proxy server 0
redhat.io registry.redhat.io/rhscl/nginx-114-rhel7 Nginx is a web server and a reverse proxy se... 0
redhat.io registry.redhat.io/rhscl/nginx-116-rhel7 Platform for running nginx 1.16 or building ... 0
redhat.io registry.redhat.io/rhscl/nginx-118-rhel7 Platform for running nginx 1.18 or building ... 0
redhat.io registry.redhat.io/ubi7/nginx-118 Platform for running nginx 1.18 or building ... 0
redhat.io registry.redhat.io/rhscl/nginx-120-rhel7 Platform for running nginx 1.20 or building ... 0
redhat.io registry.redhat.io/ubi7/nginx-120 Platform for running nginx 1.20 or building ... 0
redhat.io registry.redhat.io/3scale-amp23/apicast-gateway 3scale's API gateway (APIcast) is an OpenRe... 0
redhat.io registry.redhat.io/3scale-amp20/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.io registry.redhat.io/rhamp10/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.io registry.redhat.io/3scale-amp25/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.io registry.redhat.io/3scale-amp26/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.io registry.redhat.io/3scale-amp2/apicast-gateway-rhel8 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.io registry.redhat.io/3scale-amp20-beta/apicast-gateway 3scale's API gateway (APIcast) is an OpenRes... 0
redhat.io registry.redhat.io/3scale-amp21/apicast-gateway 3scale AMP image used for API gateway 0
redhat.io registry.redhat.io/3scale-amp24/apicast-gateway No description 0
docker.io docker.io/library/nginx Official build of Nginx. 15928 [OK]
docker.io docker.io/jwilder/nginx-proxy Automated Nginx reverse proxy for docker con... 2101 [OK]
docker.io docker.io/nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 55
docker.io docker.io/nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo... 57
docker.io docker.io/richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of... 820 [OK]
docker.io docker.io/nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN... 22
docker.io docker.io/nginxdemos/hello NGINX webserver that serves a simple page co... 79 [OK]
docker.io docker.io/privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al... 61 [OK]
docker.io docker.io/jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 145 [OK]
docker.io docker.io/mailu/nginx Mailu nginx frontend 9 [OK]
docker.io docker.io/jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho... 288
docker.io docker.io/linuxserver/nginx An Nginx container, brought to you by LinuxS... 160
docker.io docker.io/wodby/nginx Generic nginx 1 [OK]
docker.io docker.io/nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con... 29
docker.io docker.io/schmunk42/nginx-redirect A very simple container to redirect HTTP tra... 19 [OK]
docker.io docker.io/staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo... 25 [OK]
docker.io docker.io/ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 3 [OK]
docker.io docker.io/tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp... 147 [OK]
docker.io docker.io/centos/nginx-112-centos7 Platform for running nginx 1.12 or building ... 16
docker.io docker.io/alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou... 111 [OK]
docker.io docker.io/centos/nginx-18-centos7 Platform for running nginx 1.8 or building n... 13
docker.io docker.io/sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a... 7 [OK]
docker.io docker.io/bitwarden/nginx The Bitwarden nginx web server acting as a r... 11
docker.io docker.io/flashspys/nginx-static Super Lightweight Nginx Image 11 [OK]
docker.io docker.io/webdevops/nginx Nginx container 9 [OK]
# 可选项
--filter , -f Filter output based on conditions provided
# 选择starts 大于等于5000的镜像源
[root@localhost ~]# podman search nginx -f=stars=5000
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/library/nginx Official build of Nginx. 15928 [OK]
3.1.3 podman pull 下载镜像
[root@localhost ~]# podman pull docker.io/library/mysql
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Trying to pull docker.io/library/mysql...
Getting image source signatures
Copying blob 949da226cc6d done
Copying blob fa362a6aa7bd done
Copying blob 5af7cb1a200e done
Copying blob df186527fc46 done
Copying blob ffbb094f4f9e done
Copying blob bce007079ee9 done
Copying blob eab9f076e5a3 done
Copying blob 8a57a7529e8d done
Copying blob b1ccc6ed6fc7 done
Copying blob b4af75e64169 done
Copying blob 3aed6a9cd681 done
Copying blob 23390142f76f done
Copying config bbf6571db4 done
Writing manifest to image destination
Storing signatures
bbf6571db4977fe13c3f4e6289c1409fc6f98c2899eabad39bfe07cad8f64f67
# docker.io/library/mysql,这个版本是我们搜索到的,stars 最多的版本
# 默认下载最新的版本
[root@localhost ~]# podman pull mysql:5.7 # 指定某个版本下载
3.1.4 podman rmi xxx 删除镜像
podman images # 查看拉取的本地镜像
podman rmi IMAGE ID # 删除镜像
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest ffe9d497c324 6 days ago 1.46 MB
docker.io/library/mysql 5.7 738e7101490b 11 days ago 454 MB
docker.io/library/mysql latest bbf6571db497 11 days ago 521 MB
[root@localhost ~]# podman rmi 738e7101490b
Untagged: docker.io/library/mysql:5.7
Deleted: 738e7101490b45decf606211a5437ed87aa6a82f1ff03c354564bf9375ce20f9
3.2 容器命令
3.2.1 podman run 命令
docker run [可选参数] image
# 参数说明
--name = "Name" 容器名字 tomcat01,tomcat02,用来区分容器
-d 后台方式运行
-it 使用交互方式运行,进入容器查看区分
-p 指定容器的端口 -p 8080:8080
-p ip:主机端口:容器端口
-p 主机端口:容器端口(常用)
-p 容器端口
容器端口
-p 随机指定端口
[root@localhost ~]# podman run -it docker.io/library/busybox /bin/sh
/ # exit
# 容器不停止退出
Ctrl + P + Q
3.2.2 podman rm 删除容器
podman rm 容器id # 删除指定容器,不能删除正在运行的容器,如果要强制删除 rm -f
podman rm -f $(docker ps -aq) # 删除所有的容器
podman ps -aq|xargs podman rm # 删除所有的容器
3.2.3 启动和停止容器的操作
podman start 容器id # 启动容器
podman restart 容器id # 重启容器
podman stop 容器id # 停止当前正在运行的容器
podman kill 容器id # 强制停止当前容器
3.3 其他命令
3.3.1 后台启动容器
# 命令 docker run -d 镜像名
[root@localhost ~]# podman run -d centos
3.3.2 podman logs 查看日志
podman logs [OPTIONS] CONTAINER
-f : 跟踪日志输出
--since :显示某个开始时间的所有日志
-t : 显示时间戳
--tail :仅列出最新N条容器日志
# 查看某个容器,最新的10条日志信息
podman logs -ft --tail 10 d56ba5004bc5
# 查看某个容器,从某一日期到现在的所有日志
podman logs --since="2021-02-18" d56ba5004bc5
3.3.3 podman inspect xxxx 查看容器详情数据
[root@localhost ~]# podman inspect d56ba5004bc5
3.3.3 podman exec -it xxx 进入容器
# 进入容器后开启一个新的终端,可以在里面操作(常用)
docker exec -it 容器id /bin/bash
# 进入容器正在执行的终端,不会启动新的进程
docker attach 容器id