podman部署及应用
目录
podman介绍
Podman 是一个开源的容器运行时项目,可在大多数 Linux 平台上使用。Podman 提供与 Docker 非常相似的功能。正如前面提到的那样,它不需要在你的系统上运行任何守护进程,并且它也可以在没有 root 权限的情况下运行。
Podman 可以管理和运行任何符合 OCI(Open Container Initiative)规范的容器和容器镜像。Podman 提供了一个与 Docker 兼容的命令行前端来管理 Docker 镜像。[3]
Podman 不足之处:
因为没有类似 docker daemon 守护进程,所以不支持 –restart 策略,不过使用 k8s 编排就不存在这个问题
Centos8 去除了 Docker 作为默认的容器化管理工具,使用 Podman、Buildah、Skopeo 进行了替换。
podman部署
[root@localhost ~]# dnf install -y podman
Failed to set locale, defaulting to C.UTF-8
CentOS Stream 8 - AppStream 2.1 kB/s | 4.4 kB 00:02
CentOS Stream 8 - AppStream 4.4 MB/s | 24 MB 00:05
CentOS Stream 8 - BaseOS 381 B/s | 3.9 kB 00:10
CentOS Stream 8 - BaseOS 3.0 MB/s | 25 MB 00:08
CentOS Stream 8 - Extras 5.8 kB/s | 2.9 kB 00:00
Dependencies resolved.
=================================================================================================================================================================================================
Package Architecture Version Repository Size
=================================================================================================================================================================================================
Installing:
podman x86_64 2:4.0.2-1.module_el8.7.0+1106+45480ee0 appstream 13 M
Upgrading:
libsemanage x86_64 2.9-8.el8 baseos 168 k
policycoreutils x86_64 2.9-19.el8 baseos 374 k
配置加速器
[root@localhost ~]# cd /etc/containers/
[root@localhost containers]# ls
certs.d policy.json registries.conf.d storage.conf
oci registries.conf registries.d
[root@localhost containers]# vim registries.conf
unqualified-search-registries = ["docker.io"]
[[registry]]
prefix = "docker.io"
location = "https://4e3uv4d0.mirror.aliyuncs.com"
//查看加速器
[root@localhost containers]# podman info
.....................
Blocked: false
Insecure: false
Location: https://4e3uv4d0.mirror.aliyuncs.com
MirrorByDigestOnly: false
Mirrors: null
Prefix: docker.io
..............................
podman命令
[root@localhost ~]# podman pull httpd //拉取镜像
✔ docker.io/library/httpd:latest
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob 80e368ef21fc done
Copying blob 4340e7be3d7f done
Copying blob aed046121ed8 done
Copying blob 80cb79a80bbe done
Copying blob 1efc276f4ff9 done
Copying config f2a976f932 done
Writing manifest to image destination
Storing signatures
f2a976f932ec6fe48978c1cdde2c8217a497b1f080c80e49049e02757302cf74
[root@localhost ~]# podman images //查看系统中的所有镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/httpd latest f2a976f932ec 12 days ago 149 MB
[root@localhost ~]# podman diff httpd //检查映像文件系统的更改
C /usr
C /usr/local
C /usr/local/bin
A /usr/local/bin/httpd-foreground
[root@localhost ~]# podman image history httpd 显示指定镜像的历史记录
ID CREATED CREATED BY SIZE COMMENT
f2a976f932ec 12 days ago /bin/sh -c #(nop) CMD ["httpd-foreground"] 0 B
<missing> 12 days ago /bin/sh -c #(nop) EXPOSE 80 0 B
<missing> 12 days ago /bin/sh -c #(nop) COPY file:c432ff61c4993e... 3.58 kB
<missing> 12 days ago /bin/sh -c #(nop) STOPSIGNAL SIGWINCH 0 B
<missing> 12 days ago /bin/sh -c set -eux; savedAptMark="$(apt... 60.4 MB
<missing> 12 days ago /bin/sh -c #(nop) ENV HTTPD_PATCHES= 0 B
<missing> 12 days ago /bin/sh -c #(nop) ENV HTTPD_SHA256=eb397f... 0 B
<missing> 12 days ago /bin/sh -c #(nop) ENV HTTPD_VERSION=2.4.54 0 B
<missing> 12 days ago /bin/sh -c set -eux; apt-get update; apt... 5.1 MB
<missing> 12 days ago /bin/sh -c #(nop) WORKDIR /usr/local/apache2 0 B
<missing> 12 days ago /bin/sh -c mkdir -p "$HTTPD_PREFIX" && ch... 3.07 kB
<missing> 12 days ago /bin/sh -c #(nop) ENV PATH=/usr/local/apa... 0 B
<missing> 12 days ago /bin/sh -c #(nop) ENV HTTPD_PREFIX=/usr/l... 0 B
<missing> 12 days ago /bin/sh -c #(nop) CMD ["bash"] 0 B
<missing> 12 days ago /bin/sh -c #(nop) ADD file:0eae0dca665c704... 83.9 MB
[root@localhost ~]# podman image inspect httpd //显示镜像的配置
[
{
"Id": "f2a976f932ec6fe48978c1cdde2c8217a497b1f080c80e49049e02757302cf74",
"Digest": "sha256:343452ec820a5d59eb3ab9aaa6201d193f91c3354f8c4f29705796d9353d4cc6",
"RepoTags": [
"docker.io/library/httpd:latest"
],
"RepoDigests": [
"docker.io/library/httpd@sha256:343452ec820a5d59eb3ab9aaa6201d193f91c3354f8c4f29705796d9353d4cc6",
"docker.io/library/httpd@sha256:98778663b10c3952e9d7dd8a10e1ca2a8ce31f11b5f0ff9d7b3b36ddb8201db8"
],
······
"NamesHistory": [
"docker.io/library/httpd:latest"
]
}
]
[root@localhost ~]# podman image list //列出本地存储的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/httpd latest f2a976f932ec 12 days ago 149 MB
[root@localhost ~]# podman image rm httpd //删除镜像
Untagged: docker.io/library/httpd:latest
Deleted: f2a976f932ec6fe48978c1cdde2c8217a497b1f080c80e49049e02757302cf74
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@localhost ~]# podman image save busybox > busybox.tar //将镜像保存到本地
[root@localhost ~]# ls
anaconda-ks.cfg busybox.tar http.tar
[root@localhost ~]# podman image load < busybox.tar //从tar存档加载镜像
Getting image source signatures
Copying blob 084326605ab6 skipped: already exists
Copying config 7a80323521 done
Writing manifest to image destination
Storing signatures
Loaded image(s): docker.io/library/busybox:latest
[root@localhost ~]# podman image list
'REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest 7a80323521cc 2 weeks ago 1.47 MB
[root@localhost ~]# podman image prune //删除未使用的镜像
WARNING! This command removes all dangling images.
Are you sure you want to continue? [y/N] y
[root@localhost ~]# podman image search busybox //搜索镜像
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/library/busybox Busybox base image. 2712 [OK]
docker.io docker.io/rancher/busybox 0
docker.io docker.io/ibmcom/busybox 0
······
docker.io docker.io/busybox42/haraka-docker-centos CentOS Haraka build with spamassassin, redis... 1 [OK]
docker.io docker.io/busybox42/nginx_php-docker-centos This is a nginx/php-fpm server running on Ce... 1 [OK]
[root@localhost ~]# podman image tree busybox 以树格式打印镜像的图层层次结构
Image ID: 7a80323521cc
Tags: [docker.io/library/busybox:latest]
Size: 1.468MB
Image Layers
└── ID: 084326605ab6 Size: 1.463MB Top Layer of: [docker.io/library/busybox:latest]
版权声明:本文为Eternity_zzh原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。