《OpenShift / RHEL / DevSecOps 汇总目录》
运行环境
运行环境为有桌面的 CentOS Stream 9 环境,并安装有 podman 4.0(其它 Linux 使用 podman 3 也可以)。
$ yum install -y podman
使用 podman 操作 pod
- 在一个 pod 中运行 nginx 容器
podman run -dt --pod new:frontend -p 8080:80 --name nginx nginx
- 在浏览器中查看运行在 8080 端口的 nginx。

- 查看运行的 pod。
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
001057eaaf2c docker.io/library/httpd:latest httpd-foreground About an hour ago Up About an hour ago 127.0.0.1:8889->80/tcp myhttp
6f8af59721ff localhost/podman-pause:4.0.3-1648835798 22 minutes ago Up 22 minutes ago 0.0.0.0:8080->80/tcp f9053c258806-infra
60f79b9180cc docker.io/library/nginx:latest nginx -g daemon o... 22 minutes ago Up 22 minutes ago 0.0.0.0:8080->80/tcp nginx
$ podman pod list
POD ID NAME STATUS CREATED INFRA ID # OF CONTAINERS
f9053c258806 frontend Running 23 minutes ago 6f8af59721ff 2
- 根据 pod 生成 Kubernetes 的 yaml 文件。
$ podman generate kube frontend -f nginx.yaml
$ cat nginx.yaml
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-4.0.3
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2022-05-14T13:39:05Z"
labels:
app: frontend
name: frontend
spec:
containers:
5. args:
- nginx
- -g
- daemon off;
image: docker.io/library/nginx:latest
name: nginx
ports:
- containerPort: 80
hostPort: 8080
resources: {}
securityContext:
capabilities:
drop:
- CAP_MKNOD
- CAP_AUDIT_WRITE
tty: true
restartPolicy: Never
status: {}
- 关闭并删除 pod。
$ podman pod stop frontend
$ podman pod rm frontend
- 根据生成的 yaml 再次运行内含 nginx 的 pod。
$ podman play kube nginx.yaml
Pod:
cdd27cba7571bbb777f615d39773c4b6d21d057a7eeed15510810e08af30209a
Container:
b56afc02a553f2b647d06ff7fe3380c09ffd827f648dee8e556ed90e99b56fcd
- 查看 pod 中包含的容器。
$ podman pod list --ctr-names --ctr-status
POD ID NAME STATUS CREATED INFRA ID NAMES STATUS
cdd27cba7571 frontend Running 7 minutes ago 884cf9704fe1 cdd27cba7571-infra,frontend-nginx running,running
使用 Podman Desktop 伴侣
- 在 https://iongion.github.io/podman-desktop-companion/ 下载 podman-desktop-companion。
- 运行命令安装 podman-desktop-companion。
$ podman-desktop-companion-x86_64-4.1.0-rc.21.rpm
- 运行命令,启动 podman-desktop-companion。
$ podman-desktop-companion
- 在 podman-desktop-companion 窗口中确认运行环境,最后点击 Connect。

- 随即进入 podman-desktop-companion。

- 执行命令,向本地拉取一个镜像。
$ podman pull docker.io/library/httpd:latest
- 在 podman-desktop-companion 中的 Images 中可以看到上一步的镜像,然后点击 Start。在右侧窗口中提供 Container name 和端口,然后点击 Create and start。

- 然后在 Containers 中可以看到运行起来的 myhttp 容器。在该项目右侧的菜单中点击 Open terminal console 可以进入该容器。

- 在容器中可以查看 http 的 index.html 文件。另外还可通过 Open in browser 访问容器中应用的地址。

参考
https://www.redhat.com/sysadmin/podman-transfer-container-images-without-registry
https://www.redhat.com/sysadmin/podman-features-1
https://www.redhat.com/sysadmin/podman-auto-updates-rollbacks

799

被折叠的 条评论
为什么被折叠?



