Podman新手入门

安装

安装podman

centos7+可以直接使用yum进行安装

1yum -y install podman

验证安装

1podman version
2Version:            1.6.4
3RemoteAPI Version:  1
4Go Version:         go1.12.12
5OS/Arch:            linux/amd64

安装完成后,配置文件默认在/etc/containers下

1grep -Ev "^$|^#" registries.conf
2[registries.search]
3registries = ['registry.access.redhat.com', 'registry.redhat.io', 'docker.io']
4[registries.insecure]
5registries = []
6[registries.block]
7registries = []

从配置文件可以看到默认搜索红帽和docker官方的registry。可以在次添加第三方的公共registry,比如quay.io等,也可以添加一些私有仓库

基本使用

搜索镜像

1podman search nginx

下载镜像

1podman pull docker.io/library/nginx:1.16.1-alpine
2Trying to pull docker.io/library/nginx:1.16.1-alpine...
3Getting image source signatures
4Copying blob d9176111d0ef done
5Copying blob 4167d3e14976 done
6Copying config 5fad07aba1 done
7Writing manifest to image destination
8Storing signatures
95fad07aba15a1047c94b9818de93093310ed1bf2db98c185f5f8486a6e53f434

查看镜像列表

1podman images
2REPOSITORY                TAG             IMAGE ID       CREATED         SIZE
3docker.io/library/nginx   1.16.1-alpine   5fad07aba15a   10 months ago   24.9 MB

运行pod

1podman run -p 8080:80 -d docker.io/library/nginx:1.16.1-alpine
2d88d969da62641c33be2683e8be4dd78f91d35c853166c0d40a6cb09437f8ac9

访问nginx服务

 1curl http://localhost:8080
 2<!DOCTYPE html>
 3<html>
 4<head>
 5<title>Welcome to nginx!</title>
 6<style>
 7    body {
 8        width: 35em;
 9        margin: 0 auto;
10        font-family: Tahoma, Verdana, Arial, sans-serif;
11    }
12</style>
13</head>
14<body>
15<h1>Welcome to nginx!</h1>
16<p>If you see this page, the nginx web server is successfully installed and
17working. Further configuration is required.</p>
18
19<p>For online documentation and support please refer to
20<a href="http://nginx.org/">nginx.org</a>.<br/>
21Commercial support is available at
22<a href="http://nginx.com/">nginx.com</a>.</p>
23
24<p><em>Thank you for using nginx.</em></p>
25</body>
26</html>

查看运行的pod

1podman ps
2CONTAINER ID  IMAGE                                  COMMAND               CREATED         STATUS             PORTS                 NAMES
3d88d969da626  docker.io/library/nginx:1.16.1-alpine  nginx -g daemon o...  13 seconds ago  Up 12 seconds ago  0.0.0.0:8080->80/tcp  serene_ishizaka

查看日志

1podman logs d88d969da626
210.88.0.1 - - [09/Dec/2020:09:32:03 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"

停止pod

1podman stop d88d969da626

移除pod

1podman rm d88d969da626

删除镜像

1podman rmi docker.io/library/nginx:1.16.1-alpine
2Untagged: docker.io/library/nginx:1.16.1-alpine
3Deleted: 5fad07aba15a1047c94b9818de93093310ed1bf2db98c185f5f8486a6e53f434

构建镜像

可以使用Dockerfile或者其他名称,通过-f指定

1podman build -f Dockerfile -t docker.io/hzde0128/nginx:mynginx_v1 .

总结

整理来说跟docker命令行使用差不多,但是podman不需要守护进程,docker需要docker daemon作为守护进程。

更多使用方法可以通过podman --help进行查看,也可以通过访问podman官网查询帮助。