Podman实现

snow chuai汇总、整理、撰写---2020/2/15


Podman基础操作
本实验不需要安装docker服务

1) 安装podman [root@srv ~]# yum install podman -y
2) 使用podman下载镜像 [root@srv ~]# podman search centos
[root@srv ~]# podman pull centos
3) 运行容器 [root@srv ~]# podman run centos /bin/echo "Welcome to the Podman World" Welcome to the Podman World
4) 进入容器 [root@srv ~]# podman run -it centos bash [root@f41309b436ca /]#
5) 生成镜像 [root@srv ~]# podman run centos bash -c "yum -y install httpd"
[root@srv ~]# podman commit be01 snow-httpd Getting image source signatures Copying blob 0683de282177 skipped: already exists Copying blob 468c61d2adf7 done Copying config fa8ffe486a done Writing manifest to image destination Storing signatures fa8ffe486a7a57b61c1dc64936277ed73bf6136f8dbfd5e1063ed4812b0b6a8c
[root@srv ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/snow-httpd latest fa8ffe486a7a 43 seconds ago 291 MB docker.io/library/centos latest 470671670cac 4 weeks ago 245 MB
6) 运行镜像 [root@srv ~]# podman run -dt -p 80:80 localhost/snow-httpd /usr/sbin/apachectl -D FOREGROUND a8c327da36b991f7d447e2a5c0fed72372bc41c57acb48c24e3aca32c8011ce7
[root@srv ~]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a8c327da36b9 localhost/snow-httpd:latest /usr/sbin/apachec... 30 seconds ago Up 29 seconds ago 0.0.0.0:80->80/tcp laughing_feistel
# 添加index.html页面 [root@srv ~]# podman exec -it a8c3 bash -c 'echo "Hello 1000cc" > /var/www/html/index.html'
# 获取容器的IP地址 [root@srv ~]# podman inspect -l | grep \"IPAddress "IPAddress": "10.88.0.14",
# 访问测试 [root@srv ~]# curl 10.88.0.14 Hello 1000cc
# 删除容器 [root@srv ~]# podman kill a8c3 a8c327da36b991f7d447e2a5c0fed72372bc41c57acb48c24e3aca32c8011ce7
7) 挂载容器到本地系统 [root@srv ~]# podman run -itd --name snow -h snowchuai centos /bin/bash 1ebae9292cb4251e638be009bf5c29836d2f31ba31274aa5c3328cf082c7416f
[root@srv ~]# podman mount snow /var/lib/containers/storage/overlay/d799...4f3364307fcb20658/merged
[root@srv ~]# df -Th | grep merged overlay overlay 38G 2.4G 36G 7% /var/lib/containers/storage/overlay/d7995...4d34f3364307fcb20658/merged
[root@srv ~]# podman umount snow
8) 编写Dockerfile生成新镜像 [root@srv ~]# vim Dockerfile FROM centos MAINTAINER snowchuai <snow@1000cc.net>
RUN yum -y install httpd RUN echo "Hello 1000cc.net" > /var/www/html/index.html
EXPOSE 80 CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]

[root@srv ~]# podman build -t snowchuai-httpd:latest .
[root@srv ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/snowchuai-httpd latest 516fb2ceb0fd 10 seconds ago 291 MB localhost/snow-centos latest 806a42f92272 2 minutes ago 245 MB localhost/snow-httpd latest fa8ffe486a7a 18 minutes ago 291 MB docker.io/library/centos latest 470671670cac 4 weeks ago 245 MB
9) 删除所有的容器及镜像 [root@srv ~]# podman rm -f --all 1ebae9292cb4251e638be009bf5c29836d2f31ba31274aa5c3328cf082c7416f
[root@srv ~]# podman rmi -f --all fa8ffe486a7a57b61c1dc64936277ed73bf6136f8dbfd5e1063ed4812b0b6a8c 58f6fea2078182ef55b7848ced5377599849562204b2107de1dee7d353aa5987 e937be5792856f99f843ee802fd8849945162c5dc36036daa9a8626d29311662 e0e969548df6b22e96bacfda7a59e12cec050a1ab81ce8f170d3c59a3a415032 3a8429c586c803eed5524ea056aab2ee7bff592ae010430c27ccfe77b466c023 516fb2ceb0fdbd9b7e43a8e5df3f9a4a1a2c43439ba97376872870981b189270 806a42f9227276ec914bf5abf17abea37df61e59ae760ab8d8ce6d3bc5be03a8

 

如对您有帮助,请随缘打个赏。^-^

gold