podman部署及应用
podman部署及应用
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 policy.json registries.conf.d storage.conf
oci registries.conf registries.d
[root@localhost containers]# vim registries.conf
#Qunqualified-search-registries = ["registry.fedoraproject.org", "registry.access.redhat.com", "registry.centos.org", "docker.io"] //将此行注释
unqualified-search-registries = ["docker.io"] //添加下面内容
[[registry]]
location = "docker.mirrors.ustc.edu.cn"
#拉取镜像测试,docker和podman都可以拉取镜像
[root@localhost containers]# cd
[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 a2abf6c4d29d done
Copying blob 41c22baa66ec done
Copying blob 67283bbdd4a0 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
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 7a80323521cc 2 weeks ago 1.47 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 7a80323521cc 2 weeks ago 1.47 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应用
查找第一个容器镜像
[root@localhost ~]# podman search busybox
NAME DESCRIPTION
docker.io/library/busybox Busybox base image.
docker.io/rancher/busybox
docker.io/ibmcom/busybox
docker.io/openebs/busybox-client
docker.io/antrea/busybox
docker.io/ibmcom/busybox-amd64
docker.io/ibmcom/busybox-ppc64le
docker.io/yauritux/busybox-curl Busybox with CURL
docker.io/radial/busyboxplus Full-chain, Internet enabled, busybox made from scratch. Comes in git and cURL flavors.
docker.io/vukomir/busybox busybox and curl
docker.io/odise/busybox-curl
docker.io/arm64v8/busybox Busybox base image.
docker.io/amd64/busybox Busybox base image.
docker.io/busybox42/zimbra-docker-centos A Zimbra Docker image, based in ZCS 8.8.9 and CentOS 7.
docker.io/joeshaw/busybox-nonroot Busybox container with non-root user nobody
docker.io/ppc64le/busybox Busybox base image.
docker.io/p7ppc64/busybox Busybox base image for ppc64.
docker.io/s390x/busybox Busybox base image.
docker.io/prom/busybox Prometheus Busybox Docker base images
docker.io/spotify/busybox Spotify fork of https://hub.docker.com/_/busybox/ for testing helios.
docker.io/busybox42/alpine-pod
docker.io/arm32v7/busybox Busybox base image.
docker.io/i386/busybox Busybox base image.
docker.io/busybox42/haraka-docker-centos CentOS Haraka build with spamassassin, redis and some other things. Experimental still..
docker.io/busybox42/nginx_php-docker-centos This is a nginx/php-fpm server running on CentOS 7.
运行和退出 busybox 容器映像
[root@localhost ~]# podman run -it docker.io/library/busybox
/ # hostname //查看主机名
cfc296414509
/ # exit //退出
[root@localhost ~]# docker run -it docker.io/library/busybox
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
命令
(podman)(容器管理器) 全局选项、环境变量、退出代码、配置文件等
# attach 进入到正在运行的容器
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8efeb8c064f docker.io/library/httpd:latest /bin/bash About a minute ago Up About a minute ago httpd
[root@localhost ~]# podman attach c8efeb8c064f
root@c8efeb8c064f:/usr/local/apache2# exit
exit
# commit 基于已更改的容器创建镜像
[root@localhost ~]# podman commit c8efeb8c064f httpd:v0.1
Getting image source signatures
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 blob deefaa620a71 skipped: already exists
Copying blob 1227cff4b4b4 skipped: already exists
Copying config 9f7a670fed done
Writing manifest to image destination
Storing signatures
9f7a670fed8df624151acad5f1613db269d45986f9d2f771c4dbb4ed71f39908
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/httpd v0.1 9f7a670fed8d 3 seconds ago 148 MB
# container 管理容器
# cp 在容器和本地文件系统之间复制文件/文件夹
#启动一个容器查看root目录下的文件
[root@localhost ~]# podman run -it busybox
/ # ls
bin etc proc run tmp var
dev home root sys usr
#本机操作
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8efeb8c064f docker.io/library/httpd:latest /bin/bash 18 minutes ago Up 14 minutes ago httpd
36b8b7547d11 docker.io/library/busybox:latest sh 5 minutes ago Up 5 minutes ago gracious_wilbur
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# podman cp anaconda-ks.cfg 36b8b7547d11:/
#容器操作
/ # ls
anaconda-ks.cfg home sys
bin proc tmp
dev root usr
etc run var
# create 创建但不启动容器
[root@localhost ~]# podman create --name web httpd
ddd71cebbeba7e174cd5db55f9d78f03066c818c8bd9ad5a8bcf1333a4ace8ff
[root@localhost ~]# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cfc296414509 docker.io/library/busybox:latest sh 52 minutes ago Exited (0) 52 minutes ago condescending_kirch
d9569f9cf684 docker.io/library/busybox:latest sh 52 minutes ago Exited (0) 51 minutes ago zealous_yonath
c8efeb8c064f docker.io/library/httpd:latest /bin/bash 16 minutes ago Up 13 minutes ago httpd
36b8b7547d11 docker.io/library/busybox:latest sh 3 minutes ago Up 3 minutes ago gracious_wilbur
ddd71cebbeba docker.io/library/httpd:latest httpd-foreground 14 seconds ago Created
# diff 检查容器文件系统上的更改
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8efeb8c064f docker.io/library/httpd:latest /bin/bash 18 minutes ago Up 14 minutes ago httpd
36b8b7547d11 docker.io/library/busybox:latest sh 5 minutes ago Up 5 minutes ago gracious_wilbur
[root@localhost ~]# podman diff c8efeb8c064f
C /etc
C /root
A /root/.bash_history
# exec 在正在运行的容器中运行进程
[root@localhost ~]# podman exec -it 36b8b7547d11 /bin/sh
/ # ls
anaconda-ks.cfg home sys
bin proc tmp
dev root usr
etc run var
# healthcheck 管理运行状况检查
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8efeb8c064f docker.io/library/httpd:latest /bin/bash 26 minutes ago Up 22 minutes ago httpd
[root@localhost ~]# podman healthcheck run c8efeb8c064f
Error: container c8efeb8c064f289fd5576bda0addf55aab5e3844a87a06ec2c8930711051eee8 has no defined healthche
# history 显示指定图像的历史记录
[root@localhost ~]# podman 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
# image 管理图像
# images 列出本地存储中的图像
[root@localhost ~]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/httpd v0.1 9f7a670fed8d 18 minutes ago 148 MB
<none> <none> 71d146a6f2f9 20 minutes ago 148 MB
docker.io/library/busybox latest 7a80323521cc 2 weeks ago 1.47 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
# logs 获取容器的日志
[root@localhost ~]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8efeb8c064f docker.io/library/httpd:latest /bin/bash 34 minutes ago Up 30 minutes ago httpd
[root@localhost ~]# podman logs c8efeb8c064f
root@c8efeb8c064f:/usr/local/apache2#
root@c8efeb8c064f:/usr/local/apache2# exit
exit
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通