podman快速入门详解与实践

podman快速入门详解与实践

podman简介

Podman 原来是 CRI-O 项目的一部分,后来被分离成一个单独的项目叫 libpod。Podman 的使用体验和 Docker 类似,不同的是 Podman 没有 daemon。以前使用 Docker CLI 的时候,Docker CLI 会通过 gRPC API 去跟 Docker Engine 说「我要启动一个容器」,然后 Docker Engine 才会通过 OCI Container runtime(默认是 runc)来启动一个容器。这就意味着容器的进程不可能是 Docker CLI 的子进程,而是 Docker Engine 的子进程。

Podman 比较简单粗暴,它不使用 Daemon,而是直接通过 OCI runtime(默认也是 runc)来启动容器,所以容器的进程是 podman 的子进程。这比较像 Linux 的 fork/exec 模型,而 Docker 采用的是 C/S(客户端/服务器)模型。与 C/S 模型相比,fork/exec 模型有很多优势,比如:

  • 系统管理员可以知道某个容器进程到底是谁启动的。
  • 如果利用 cgroup 对 podman 做一些限制,那么所有创建的容器都会被限制。
  • SD_NOTIFY : 如果将 podman 命令放入 systemd 单元文件中,容器进程可以通过 podman
    返回通知,表明服务已准备好接收任务。
  • socket 激活 : 可以将连接的 socket 从 systemd 传递到 podman,并传递到容器进程以便使用它们。

Podman 兼容 Docker吗?
大部分是兼容的,例如:

1.可以直接使用 Docker 镜像

2.命令非常相似

如果你非常怀念 docker命令,甚至可以给 Podman 设置别名为 docker:

echo "alias docker=podman" >> .bashrc

source .bashrc

可以说podman大部分的命令与docker几乎一样
安装podman

yum -y install pod man

查看版本号


[root@ok ~]# podman -v
podman version 1.6.4

podman默认网段
10.88.0.1/16

10: cni-podman0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 1a:76:c4:35:8d:39 brd ff:ff:ff:ff:ff:ff
    inet 10.88.0.1/16 brd 10.88.255.255 scope global cni-podman0
       valid_lft forever preferred_lft forever

命令详解


[root@ok ~]# podman --help
manage pods and images

Usage:
  podman [flags]
  podman [command]

Available Commands:
  attach      Attach to a running container
  build       Build an image using instructions from Containerfiles
  commit      Create new image based on the changed container
  container   Manage Containers
  cp          Copy files/folders between a container and the local filesystem
  create      Create but do not start a container
  diff        Inspect changes on container's file systems
  events      Show podman events
  exec        Run a process in a running container
  export      Export container's filesystem contents as a tar archive
  generate    Generated structured data
  healthcheck Manage Healthcheck
  help        Help about any command
  history     Show history of a specified image
  image       Manage images
  images      List images in local storage
  import      Import a tarball to create a filesystem image
  info        Display podman system information
  init        Initialize one or more containers
  inspect     Display the configuration of a container or image
  kill        Kill one or more running containers with a specific signal
  load        Load an image from container archive
  login       Login to a container registry
  logout      Logout of a container registry
  logs        Fetch the logs of a container
  mount       Mount a working container's root filesystem
  network     Manage Networks
  pause       Pause all the processes in one or more containers
  play        Play a pod
  pod         Manage pods
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image from a registry
  push        Push an image to a specified destination
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Removes one or more images from local storage
  run         Run a command in a new container
  save        Save image to an archive
  search      Search registry for image
  start       Start one or more containers
  stats       Display a live stream of container resource usage statistics
  stop        Stop one or more containers
  system      Manage podman
  tag         Add an additional name to a local image
  top         Display the running processes of a container
  umount      Unmounts working container's root filesystem
  unpause     Unpause the processes in one or more containers
  unshare     Run a command in a modified user namespace
  varlink     Run varlink interface
  version     Display the Podman Version Information
  volume      Manage volumes
  wait        Block on one or more containers

Flags:
      --cgroup-manager string     Cgroup manager to use (cgroupfs or systemd) (default "systemd")
      --cni-config-dir string     Path of the configuration directory for CNI networks
      --config string             Path of a libpod config file detailing container server configuration options
      --conmon string             Path of the conmon binary
      --cpu-profile string        Path for the cpu profiling results
      --events-backend string     Events backend to use
      --help                      Help for podman
      --hooks-dir strings         Set the OCI hooks directory path (may be set multiple times)
      --log-level string          Log messages above specified level: debug, info, warn, error, fatal or panic (default "error")
      --namespace string          Set the libpod namespace, used to create separate views of the containers and pods on the system
      --network-cmd-path string   Path to the command for configuring the network
      --root string               Path to the root directory in which data, including images, is stored
      --runroot string            Path to the 'run directory' where all state information is stored
      --runtime string            Path to the OCI-compatible binary used to run containers, default is /usr/bin/runc
      --storage-driver string     Select which storage driver is used to manage storage of images and containers (default is overlay)
      --storage-opt stringArray   Used to pass an option to the storage driver
      --syslog                    Output logging information to syslog as well as the console
      --tmpdir string             Path to the tmp directory
      --trace                     Enable opentracing output
  -v, --version                   Version of podman

Use "podman [command] --help" for more information about a command.

podman使用阿里云镜像加速


国内直接用 podman pull 拉取镜像会很慢,所以需要配置阿里云容器镜像来加速访问
Podman 默认注册表配置文件在 /etc/containers/registries.conf
清空并修改为以下内容:

unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "******.mirror.aliyuncs.com"

把 location 对应的值修改为你的阿里云容器加速镜像地址就可以了,现在拉取镜像就是用的阿里云加速

pull镜像并运行
下载镜像

podman pull nginx

查看镜像

[root@ok system]# podman images
REPOSITORY                TAG      IMAGE ID       CREATED        SIZE
docker.io/library/nginx   latest   f6d0b4767a6c   2 months ago   137 MB

运行容器

[root@ok system]# podman run -itd --name nginx -p 9999:80 f6d0b4767a6c
15122785bee25e2987bbc0dff7060ff5b36e7f6cf994a72ef3a3ab3827ffa4b9
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/101785.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 网站开发团队成员(项目团队)

    1.项目带头人(Boss):通常是项目的发起人,为项目规划企业战略目标,对项目的成败负最终责任。2.项目经理:这个不用说了是项目当然需要PM,建议是通过PMP认证的项目经理,主要负责项目各个过程的管理,以及过程优化降低开发风险。 3.系统架构师:架构师不单单是技术架构,还

    2022年4月10日
    134
  • Ubuntu安装Jdk环境

    Ubuntu安装Jdk环境1、去官网下载所需版本官网链接2、解压tar-zxvfjdk-8u111-linux-x64.tar.gz3、移动位置sudomvjdk1.8.0_111/usr/local/jdk1.84、设置环境变量exportJAVA_HOME=/usr/local/jdk1.8exportJRE_HOME=${JAVA_HOME}/jreexportCLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libexportPATH=.:${JAVA

    2022年7月14日
    12
  • Android sha1_android studio打包apk教程

    Android sha1_android studio打包apk教程开发版sha1方法一:打开AndroidStudio的Terminal窗口,进入.android目录(默认是在C:\Users\Administrator.android目录下),输入如下命令:keytool-v-list-keystoredebug.keystore方法二:在AndroidStudio右边找到Gradle,点开(图片不够大,右键,新窗口打开)接下来发布版版sh

    2022年8月10日
    5
  • OleDbCommand 的用法

    OleDbCommand 的用法OleDbConnectioncon=newOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;datasource=data.mdb

    2022年7月4日
    23
  • java .gml格式_NetworkX之输入文件GML「建议收藏」

    java .gml格式_NetworkX之输入文件GML「建议收藏」之前看过networkx,igraph都说支持GML格式文件输入形式,直到今天想再Nepidemixload进文件进行分析,发现Nepidemix 对load输入文件要求是GML和gpickle,其余的不支持。所以查阅了下GML究竟是什么。GML(GraphModellingLanguage):Therearemanydifferentprogramsthatworkwith…

    2025年7月6日
    0
  • Odin Inspector 系列教程 — 常见问题解答(FAQ)

    Odin Inspector 系列教程 — 常见问题解答(FAQ)1.Odin多达约90种不同的特性,有可以快速预览每种特性的效果吗?可以选择Tools/OdinInspector/AttributeOverview进行快速预览,如果需要更详细的说明,可以查看主页革命性Unity编辑器扩展工具—OdinInspector系列教程,配合示例工程服用效果更佳2.可以禁用指定的Odin绘制特性吗?Odin…

    2022年7月21日
    15

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号