podman部署
[root@localhost ~]# dnf -y install podman-docker
//有podman和docker的命令
[root@localhost ~]# which podman
/usr/bin/podman
[root@localhost ~]# which docker
/usr/bin/docker
//但是并没有安装docker,安装的是podman-docker
[root@localhost ~]# rpm -qa|grep docker
podman-docker-4.0.2-1.module_el8.7.0+1106+45480ee0.noarch
//可以看出docker是shell脚本,podman是一个程序
[root@localhost ~]# file /usr/bin/docker
/usr/bin/docker: POSIX shell script, ASCII text executable
[root@localhost ~]# file /usr/bin/podman
/usr/bin/podman: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=16ee99ff383f7fb24a2fc7d97880bb15637bb88e, stripped
//设置一个拉取镜像的默认仓库和配置镜像加速器
[root@localhost ~]# cd /etc/containers/
[root@localhost containers]# ls
certs.d registries.conf storage.conf
oci registries.conf.d
policy.json registries.d
[root@localhost containers]# vim registries.conf
#unqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "registry.centos.org", "docker.io"] //将此行注释
unqualified-search-registries = ["docker.io"] //添加下面内容
[[registry]]
prefix = "docker.io"
location = "docker.mirrors.ustc.edu.cn"
//拉取镜像测试,docker和podman都可以拉取镜像
[root@localhost ~]# docker pull httpd
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Resolving "httpd" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob d982c879c57e done
Copying blob dcc4698797c8 done
Copying blob 41c22baa66ec done
Copying blob 67283bbdd4a0 done
Copying blob a2abf6c4d29d done
Copying config dabbfbe0c5 done
Writing manifest to image destination
Storing signatures
dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34
[root@localhost ~]# podman pull centos
Resolved "centos" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull quay.io/centos/centos:latest...
Getting image source signatures
CopyCopying blob 7a0437f04f83 [>-----------] 7.9MiB / 71.
Copying blob 7a0437f04f83 done
Copying config 300e315adb done
Writing manifest to image destination
Storing signatures
300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest beae173ccac6 7 months ago 1.46 MB
docker.io/library/httpd latest dabbfbe0c57b 7 months ago 148 MB
quay.io/centos/centos latest 300e315adb2f 20 months ago 217 MB
//上面拉取镜像过程中发现拉取centos镜像时,默认在红帽镜像仓库拉取,若想自定义仓库拉取在拉取时将仓库地址写明即可
[root@localhost ~]# podman pull docker.io/library/centos
Trying to pull docker.io/library/centos:latest...
Getting image source signatures
Copying blob a1d0c7532777 done
Copying config 5d0da3dc97 done
Writing manifest to image destination
Storing signatures
5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/busybox latest beae173ccac6 7 months ago 1.46 MB
docker.io/library/httpd latest dabbfbe0c57b 7 months ago 148 MB
docker.io/library/centos latest 5d0da3dc9764 11 months ago 239 MB
quay.io/centos/centos latest 300e315adb2f 20 months ago 217 MB
podman应用
//podman search 搜索镜像
[root@localhost ~]# podman search httpd
NAME DESCRIPTION
docker.io/library/httpd The Apache HTTP Server Project
docker.io/clearlinux/httpd httpd HyperText Transfer Protocol (HTTP) server program with the benefits of Clear Linux OS
docker.io/centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or building httpd-based application
docker.io/manageiq/httpd Container with httpd, built on CentOS for ManageIQ.
docker.io/centos/httpd-24-centos8
docker.io/dockerpinata/httpd
docker.io/19022021/httpd-connection_test This httpd image will test the connectivity of the endpoint.
docker.io/publici/httpd httpd:latest
docker.io/paketobuildpacks/httpd
docker.io/manasip/httpd
docker.io/httpdocker/kubia
docker.io/centos/httpd
docker.io/e2eteam/httpd
docker.io/patrickha/httpd-err
docker.io/hypoport/httpd-cgi httpd-cgi
docker.io/solsson/httpd-openidc mod_auth_openidc on official httpd image, verified with Keycloak using docker-compose
docker.io/dariko/httpd-rproxy-ldap Apache httpd reverse proxy with LDAP authentication
docker.io/amd64/httpd The Apache HTTP Server Project
docker.io/manageiq/httpd_configmap_generator Httpd Configmap Generator
docker.io/inanimate/httpd-ssl A play container with httpd, ssl enabled, and PLAY certs incorporated!
docker.io/httpdss/archerysec ArcherySec repository
docker.io/lead4good/httpd-fpm httpd server which connects via fcgi proxy handler to a php-fpm container at $PHP_HOST:9000
docker.io/jonathanheilmann/httpd-alpine-rewrite httpd:alpine with enabled mod_rewrite
docker.io/sandeep1988/httpd-new httpd-new
docker.io/nnasaki/httpd-ssi SSI enabled Apache 2.4 on Alpine Linux
//podman pull拉取镜像
[root@localhost ~]# podman pull httpd
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob d982c879c57e skipped: already exists
Copying blob a2abf6c4d29d skipped: already exists
Copying blob dcc4698797c8 skipped: already exists
Copying blob 41c22baa66ec skipped: already exists
Copying blob 67283bbdd4a0 skipped: already exists
Copying config dabbfbe0c5 done
Writing manifest to image destination
Storing signatures
dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34
//podman images 查看镜像
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/httpd latest dabbfbe0c57b 7 months ago 148 MB
//podman create 创建容器
[root@localhost ~]# podman create httpd
0136262d35ca674be2b8249941f2144850f16450d61aaf75e2b7fe1180c0ab12
//podman ps 查看容器
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0136262d35ca docker.io/library/httpd:latest httpd-foreground 39 seconds ago Created eloquent_tu
//podman rm 删除容器
[root@localhost ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0136262d35ca docker.io/library/httpd:latest httpd-foreground About a minute ago Created eloquent_tu
[root@localhost ~]# podman rm 0136262d35ca
0136262d35ca674be2b8249941f2144850f16450d61aaf75e2b7fe1180c0ab12
[root@localhost ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@localhost ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58f66b635cac docker.io/library/httpd:latest httpd-foreground 24 minutes ago Exited (0) 22 minutes ago infallible_dijkstra
[root@localhost ~]# podman rm -f 58f66b635cac
58f66b635cacee39cb23063df03ccc4a678c4c6269f46e5add4d581f0ff6b4d7
[root@localhost ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
//podman rmi 删除镜像
[root@localhost ~]# podman rmi -f httpd
Untagged: docker.io/library/httpd:latest
Deleted: dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34
//podman run 创建一个运行的容器
[root@localhost ~]# podman run -it --name web httpd /bin/bash
Resolving "httpd" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob dcc4698797c8 done
Copying blob a2abf6c4d29d done
Copying blob 41c22baa66ec done
Copying blob d982c879c57e done
Copying blob 67283bbdd4a0 done
Copying config dabbfbe0c5 done
Writing manifest to image destination
Storing signatures
root@1508bc82592b:/usr/local/apache2#
--name 容器名 //指定容器名
--label 标记名 //加标记方便查找
-it //让容器的输入保持打开状态,并分配终端
-c //不进行登录执行命令
-d //将容器放入后台进行执行
-v //可以创建多个数据卷
也可挂载到宿主机的目录,如果本地没有目录,则自动生成一个目录
挂载方法 //宿主机目录:docker数据卷
-p //映射端口 宿主机端:容器端口
-P //发布所有公开的端口(随机映射端口号)
--volumes-from //容器和容器之间建立联系
----restart always //永久开启容器,服务重启后容器也会启动,不会关闭
--rm //一次性容器,退出后直接删除
//podman diff 检查容器文件系统上的更改
[root@localhost ~]# podman diff web
C /root
A /root/.bash_history
C /etc
//podman image history 显示指定镜像的历史记录
[root@localhost ~]# podman image history httpd
ID CREATED CREATED BY SIZE COMMENT
dabbfbe0c57b 7 months ago /bin/sh -c #(nop) CMD ["httpd-foreground"] 0 B
<missing> 7 months ago /bin/sh -c #(nop) EXPOSE 80 0 B
<missing> 7 months ago /bin/sh -c #(nop) COPY file:c432ff61c4993e... 3.58 kB
<missing> 7 months ago /bin/sh -c #(nop) STOPSIGNAL SIGWINCH 0 B
<missing> 7 months ago /bin/sh -c set -eux; savedAptMark="$(apt... 61.1 MB
<missing> 7 months ago /bin/sh -c #(nop) ENV HTTPD_PATCHES= 0 B
<missing> 7 months ago /bin/sh -c #(nop) ENV HTTPD_SHA256=0127f7... 0 B
<missing> 7 months ago /bin/sh -c #(nop) ENV HTTPD_VERSION=2.4.52 0 B
<missing> 7 months ago /bin/sh -c set -eux; apt-get update; apt... 2.72 MB
<missing> 7 months ago /bin/sh -c #(nop) WORKDIR /usr/local/apache2 0 B
<missing> 7 months ago /bin/sh -c mkdir -p "$HTTPD_PREFIX" && ch... 3.07 kB
<missing> 7 months ago /bin/sh -c #(nop) ENV PATH=/usr/local/apa... 0 B
<missing> 7 months ago /bin/sh -c #(nop) ENV HTTPD_PREFIX=/usr/l... 0 B
<missing> 7 months ago /bin/sh -c #(nop) CMD ["bash"] 0 B
<missing> 7 months ago /bin/sh -c #(nop) ADD file:09675d11695f65c... 83.9 MB
//显示容器或镜像的配置
[root@localhost ~]# podman inspect httpd
[
{
"Id": "dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34",
......
"NamesHistory": [
"docker.io/library/httpd:latest"
]
}
]
//登录镜像仓库
[root@localhost ~]# podman login docker.io
Username: chengxinwang
Password:
Login Succeeded!
//登出镜像仓库
[root@localhost ~]# podman logout docker.io
Removed login credentials for docker.io
//将镜像保存到本地
[root@localhost ~]# podman image save httpd > httod.tar
[root@localhost ~]# ls
123 456 abc anaconda-ks.cfg httod.tar
//从tar归档中加载镜像
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/httpd latest dabbfbe0c57b 7 months ago 148 MB
[root@localhost ~]# podman rmi httpd
Untagged: docker.io/library/httpd:latest
Deleted: dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@localhost ~]# podman image load < httod.tar
Getting image source signatures
Copying blob deefaa620a71 skipped: already exists
Copying blob 2edcec3590a4 skipped: already exists
Copying blob 1da636a1aa95 skipped: already exists
Copying blob 15e4bf5d0804 skipped: already exists
Copying blob 9cff3206f9a6 skipped: already exists
Copying config dabbfbe0c5 done
Writing manifest to image destination
Storing signatures
Loaded image(s): docker.io/library/httpd:latest
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/httpd latest dabbfbe0c57b 7 months ago 148 MB
//启动一个或多个
[root@localhost ~]# podman start web
web
//停止一个或多个
[root@localhost ~]# podman stop web
web
//重启
[root@localhost ~]# podman restart web
1508bc82592b6b9ba25f8ce4c981e19b513a3e1d75b4610636769a4133bf18a3
//连接到运行的容器
[root@localhost ~]# podman attach web
root@1508bc82592b:/usr/local/apache2# //在正在运行的容器中运行命令
[root@localhost ~]# podman exec -it web /bin/bash
root@1508bc82592b:ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var