• PodMan容器技术


    容器 

    容器技术

    软件应用通常依赖于运行时环境提供的系统库、配置文件或服务。传统上,软件应用的运行时环境安装 在物理主机或虚拟机上运行的操作系统中。

    然后,管理员在操作系统上安装应用依赖项。 在RHEL中,诸如 RPM 等打包系统可协助管理员管理相关依赖项。安装 httpd 软件包时,RPM 系统会确 保同时安装该软件包的正确库和其他依赖项。

    以传统方式部署的软件应用的主要弊端时这些依赖项会受到运行时环境的束缚。应用需要的支持软件的 版本可能比操作系统提供的软件更旧或更新。

    同样,同一系统上的两个应用可能需要同一软件互不兼容 的不同版本。 解决这些冲突的方式之一是将应用打包并作为容器进行部署。容器是由一个或多个与系统其余部分隔离 的进程组成的集合。软件容器是打包应用以简化其部署和管理的一种方式。

    以实体集装箱为例,集装箱是打包和装运货物的标准方式。它作为一个箱子进行标记、装载、卸载,以 及从一个位置运输到另一个位置。集装箱中的内容与其他集装箱的内容隔离,因此互不影响。这些基本 原则也适用于软件容器。 RHEL 通过运用以下核心技术来支持容器:

    • 用于资源管理的控制组(cgroup)
    • 用于进程隔离的命名空间(namespace)
    • 加强安全边界的SELinux 和 Secomp(安全计算模式)

    Rootless 和 Rootful 容器

            在容器主机上,你可以 root 用户或普通非特权用户身份运行容器。由特权用户运行的容器称为 Rootful 容器。由非特权用户运行的容器称为 Rootless 容器。 Rootless 容器不允许使用通常为特权用户保留的系统资源,例如访问受限目录,或在受限端口(1024以 下的端口)上发布网络服务。此功能可防止潜在攻击者获取容器主机上的 root 权限。 

    容器管理工具

    RHEL 提供了一组容器工具,可用于在单一服务器上运行多个容器。

    • podman 管理容器和容器镜像
    • skopeo 检查、复制、删除和签署镜像
    • buildah 创建容器镜像

    这些工具与开放容器项目(OCI)兼容。借助这些工具,你可以管理由兼容 OCI 的容器引擎(如 Podman 或 Docker)创建的任何 Linux 容器。这些工具专门设计用于在单节点容器主机上的 RHEL 下运 行容器。

    部署容器

    Podman 实用程序 Podman 是来自 container-tools 元数据包的全功能容器引擎,用于管理开放容器计划容器和镜像。 podman 实用程序的运作不使用守护进程,因此开发人员无需系统上的特权用户账户来启动和停止容 器。Podman 提供多个子命令来与容器和镜像交互。以下列表显示了一些使用的子命令。

    安装容器使用工具

    1. # dnf install container-tools -y
    2. # dnf info container-tools

    从注册表下载容器镜像文件

    1. [root@service ~]# podman info
    2. host:
    3. arch: amd64
    4. buildahVersion: 1.33.5
    5. cgroupControllers:
    6. - cpuset
    7. - cpu
    8. - io
    9. - memory
    10. - hugetlb
    11. - pids
    12. - rdma
    13. - misc
    14. cgroupManager: systemd
    15. cgroupVersion: v2
    16. conmon:
    17. package: conmon-2.1.10-1.el9.x86_64
    18. path: /usr/bin/conmon
    19. version: 'conmon version 2.1.10, commit: 5c6ed42ed821d0a028d0006e6f9c8a69ae0806ab'
    20. cpuUtilization:
    21. idlePercent: 75.99
    22. systemPercent: 6.7
    23. userPercent: 17.3
    24. cpus: 2
    25. databaseBackend: sqlite
    26. distribution:
    27. distribution: rhel
    28. version: "9.1"
    29. eventLogger: journald
    30. freeLocks: 2048
    31. hostname: service
    32. idMappings:
    33. gidmap: null
    34. uidmap: null
    35. kernel: 5.14.0-162.6.1.el9_1.x86_64
    36. linkmode: dynamic
    37. logDriver: journald
    38. memFree: 232144896
    39. memTotal: 1828413440
    40. networkBackend: netavark
    41. networkBackendInfo:
    42. backend: netavark
    43. dns:
    44. package: aardvark-dns-1.9.0-1.el9.x86_64
    45. path: /usr/libexec/podman/aardvark-dns
    46. version: aardvark-dns 1.9.0
    47. package: netavark-1.10.3-1.el9.x86_64
    48. path: /usr/libexec/podman/netavark
    49. version: netavark 1.10.3
    50. ociRuntime:
    51. name: crun
    52. package: crun-1.14.3-1.el9.x86_64
    53. path: /usr/bin/crun
    54. version: |-
    55. crun version 1.14.3
    56. commit: 1961d211ba98f532ea52d2e80f4c20359f241a98
    57. rundir: /run/user/0/crun
    58. spec: 1.0.0
    59. +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
    60. os: linux
    61. pasta:
    62. executable: ""
    63. package: ""
    64. version: ""
    65. remoteSocket:
    66. exists: false
    67. path: /run/podman/podman.sock
    68. security:
    69. apparmorEnabled: false
    70. capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    71. rootless: false
    72. seccompEnabled: true
    73. seccompProfilePath: /usr/share/containers/seccomp.json
    74. selinuxEnabled: true
    75. serviceIsRemote: false
    76. slirp4netns:
    77. executable: /usr/bin/slirp4netns
    78. package: slirp4netns-1.2.3-1.el9.x86_64
    79. version: |-
    80. slirp4netns version 1.2.3
    81. commit: c22fde291bb35b354e6ca44d13be181c76a0a432
    82. libslirp: 4.4.0
    83. SLIRP_CONFIG_VERSION_MAX: 3
    84. libseccomp: 2.5.2
    85. swapFree: 3140481024
    86. swapTotal: 4001361920
    87. uptime: 0h 24m 14.00s
    88. variant: ""
    89. plugins:
    90. authorization: null
    91. log:
    92. - k8s-file
    93. - none
    94. - passthrough
    95. - journald
    96. network:
    97. - bridge
    98. - macvlan
    99. - ipvlan
    100. volume:
    101. - local
    102. registries:
    103. search:
    104. - registry.access.redhat.com
    105. - registry.redhat.io
    106. - docker.io
    107. store:
    108. configFile: /etc/containers/storage.conf
    109. containerStore:
    110. number: 0
    111. paused: 0
    112. running: 0
    113. stopped: 0
    114. graphDriverName: overlay
    115. graphOptions:
    116. overlay.mountopt: nodev,metacopy=on
    117. graphRoot: /var/lib/containers/storage
    118. graphRootAllocated: 17060331520
    119. graphRootUsed: 8712081408
    120. graphStatus:
    121. Backing Filesystem: xfs
    122. Native Overlay Diff: "false"
    123. Supports d_type: "true"
    124. Supports shifting: "false"
    125. Supports volatile: "true"
    126. Using metacopy: "true"
    127. imageCopyTmpDir: /var/tmp
    128. imageStore:
    129. number: 0
    130. runRoot: /run/containers/storage
    131. transientStore: false
    132. volumePath: /var/lib/containers/storage/volumes
    133. version:
    134. APIVersion: 4.9.3-dev
    135. Built: 1707216158
    136. BuiltTime: Tue Feb 6 18:42:38 2024
    137. GitCommit: ""
    138. GoVersion: go1.21.3
    139. Os: linux
    140. OsArch: linux/amd64
    141. Version: 4.9.3-dev

     搜索镜像

    1. [root@service ~]# podman search python
    2. NAME DESCRIPTION
    3. registry.access.redhat.com/ubi8/python-27 Platform for building and running Python 2.7...
    4. registry.access.redhat.com/ubi8/python-36 Platform for building and running Python 3.6...
    5. registry.access.redhat.com/ubi8/python-38 Platform for building and running Python 3.8...
    6. registry.access.redhat.com/ubi8/python-39 Platform for building and running Python 3.9...
    7. registry.access.redhat.com/ubi9/python-39 rhcc_registry.access.redhat.com_ubi9/python-...
    8. registry.access.redhat.com/ubi9/python-311 rhcc_registry.access.redhat.com_ubi9/python-...
    9. registry.access.redhat.com/openshift3/python-33-rhel7 Python 3.3 platform for building and running...
    10. registry.access.redhat.com/ubi8/python-311 rhcc_registry.access.redhat.com_ubi8/python-...
    11. registry.access.redhat.com/rhscl/python-35-rhel7 Python 3.5 platform for building and running...
    12. registry.access.redhat.com/rhscl/python-27-rhel7 Python 2.7 platform for building and running...
    13. registry.access.redhat.com/rhscl/python-34-rhel7 Python 3.4 platform for building and running...
    14. registry.access.redhat.com/rhscl/python-36-rhel7 Python 3.6 available as container is a base...
    15. registry.access.redhat.com/ubi7/python-27 Python 2.7 platform for building and running...
    16. registry.access.redhat.com/ubi7/python-36 Platform for building and running Python 3.6...
    17. registry.access.redhat.com/ubi7/python-38 Python 3.8 platform for building and running...
    18. registry.access.redhat.com/codeready-workspaces/stacks-python "Red Hat CodeReady Workspaces- Python Stack...
    19. registry.access.redhat.com/codeready-workspaces-beta/stacks-python Red Hat CodeReady Workspaces- Python Stack c...
    20. registry.access.redhat.com/rhel7-atomic Red Hat Enterprise Linux Atomic Image is a m...
    21. registry.access.redhat.com/rhel7/rhel-atomic Red Hat Enterprise Linux Atomic Image is a m...
    22. registry.access.redhat.com/rhel-atomic Red Hat Enterprise Linux Atomic Image is a m...
    23. registry.access.redhat.com/rhel7-minimal Red Hat Enterprise Linux Minimal Image is a...
    24. registry.access.redhat.com/rhel-minimal Red Hat Enterprise Linux Minimal Image is a...
    25. registry.access.redhat.com/rhel7-rhel-minimal Red Hat Enterprise Linux Minimal Image is a...
    26. registry.access.redhat.com/rhscl/s2i-base-rhel7 Base image delivers all the essential librar...
    27. registry.access.redhat.com/ubi8/s2i-base Base image with essential libraries and tool...
    28. registry.redhat.io/rhel8/python-27 Python 2.7 available as container is a base...
    29. registry.redhat.io/rhel8/python-36 Python 3.6 available as container is a base...
    30. registry.redhat.io/ubi8/python-27 Platform for building and running Python 2.7...
    31. registry.redhat.io/ubi8/python-36 Platform for building and running Python 3.6...
    32. registry.redhat.io/ubi8/python-38 Platform for building and running Python 3.8...
    33. registry.redhat.io/rhel8/python-38 Platform for building and running Python 3.8...
    34. registry.redhat.io/rhel8/python-39 Platform for building and running Python 3.9...
    35. registry.redhat.io/ubi8/python-39 Platform for building and running Python 3.9...
    36. registry.redhat.io/rhel9/python-39 rhcc_registry.access.redhat.com_rhel9/python...
    37. registry.redhat.io/ubi9/python-39 rhcc_registry.access.redhat.com_ubi9/python-...
    38. registry.redhat.io/rhel8/python-311 rhcc_registry.access.redhat.com_rhel8/python...
    39. registry.redhat.io/rhel9/python-311 rhcc_registry.access.redhat.com_rhel9/python...
    40. registry.redhat.io/ubi9/python-311 rhcc_registry.access.redhat.com_ubi9/python-...
    41. registry.redhat.io/openshift3/python-33-rhel7 Python 3.3 platform for building and running...
    42. registry.redhat.io/ubi8/python-311 rhcc_registry.access.redhat.com_ubi8/python-...
    43. registry.redhat.io/ansible-automation-platform-21/ansible-python-base-rhel8 Base python container for ansible-builder
    44. registry.redhat.io/ansible-automation-platform-23/ansible-python-base-rhel8 rhcc_registry.access.redhat.com_ansible-auto...
    45. registry.redhat.io/ansible-automation-platform-23/ansible-python-toolkit-rhel8 rhcc_registry.access.redhat.com_ansible-auto...
    46. registry.redhat.io/ansible-automation-platform-24/ansible-python-base-rhel9 rhcc_registry.access.redhat.com_ansible-auto...
    47. registry.redhat.io/ansible-automation-platform-24/ansible-python-toolkit-rhel9 rhcc_registry.access.redhat.com_ansible-auto...
    48. registry.redhat.io/ansible-automation-platform-20-early-access/ansible-python-base-rhel8 Base python container for ansible-builder
    49. registry.redhat.io/ansible-automation-platform-20-early-access/ansible-python-toolkit-rhel8 Python builder container for ansible-builder
    50. registry.redhat.io/ansible-automation-platform-21/ansible-python-toolkit-rhel8 Python builder container for ansible-builder
    51. registry.redhat.io/ansible-automation-platform-22/ansible-python-base-rhel8 rhcc_registry.access.redhat.com_ansible-auto...
    52. registry.redhat.io/ansible-automation-platform-22/ansible-python-toolkit-rhel8 rhcc_registry.access.redhat.com_ansible-auto...
    53. docker.io/library/python Python is an interpreted, interactive, objec...
    54. docker.io/library/hylang Hy is a Lisp dialect that translates express...
    55. docker.io/library/pypy PyPy is a fast, compliant alternative implem...
    56. docker.io/bitnami/python Bitnami Python Docker Image
    57. docker.io/cimg/python
    58. docker.io/okteto/python
    59. docker.io/appdynamics/python-agent-init AppDynamics Repository for Python agent inst...
    60. docker.io/rapidfort/python-chromedriver
    61. docker.io/intel/python
    62. docker.io/pachyderm/python-build
    63. docker.io/pachyderm/python-sdk-ci-testing
    64. docker.io/airbyte/python-connector-base
    65. docker.io/clearlinux/python Python programming interpreted language with...
    66. docker.io/faucet/python3 Python3 docker image for amd64
    67. docker.io/openwhisk/python3action Apache OpenWhisk runtime for Python 3 Action...
    68. docker.io/openwhisk/python2action Apache OpenWhisk runtime for Python v2 Actio...
    69. docker.io/mirantis/python-operations-api https://mirantis.jira.com/browse/IT-40189
    70. docker.io/opensuse/python openSUSE base image with python
    71. docker.io/submitty/python Official Repository for Submitty Python Imag...
    72. docker.io/okteto/python-fastapi
    73. docker.io/fnndsc/python-poetry Python Poetry
    74. docker.io/ubuntu/python A chiselled Ubuntu rock with the Python runt...
    75. docker.io/pipelinecomponents/python-safety Safety by pyup.io for Python in a container...
    76. docker.io/openwhisk/python3aiaction Apache OpenWhisk runtime for Python 3 Action...
    77. docker.io/okteto/python-job-launcher

    下载镜像

    1. [root@service ~]# podman pull docker.io/library/python
    2. Trying to pull docker.io/library/python:latest...
    3. Getting image source signatures
    4. Copying blob e1aa7eb23da8 done |
    5. Copying blob 7bb465c29149 done |
    6. Copying blob 49b40be4436e done |
    7. Copying blob 2b9b41aaa3c5 done |
    8. Copying blob c558fac597f8 done |
    9. Copying blob 11402150a57e done |
    10. Copying blob 297428e82567 done |
    11. Copying blob 28e810024ad5 done |
    12. Copying config a3aef63c6c done |
    13. Writing manifest to image destination
    14. a3aef63c6c1029222ff635a72a0fcaddba1fd7a26abdf2491ace8eb3c654471e

    查看镜像

    1. [root@service ~]# podman images
    2. REPOSITORY TAG IMAGE ID CREATED SIZE
    3. docker.io/library/python latest a3aef63c6c10 4 weeks ago 1.04 GB

    从容器文件创建容器镜像

    1. [root@service ~]# vim Containerfile
    2. FROM registry.access.redhat.com/ubi9/ubi:latest
    3. RUN dnf install -y python39
    4. CMD ["/bin/bash","-c","sleep infinity"]
    1. [root@service ~]# podman build -t python39:1.0 .
    2. STEP 1/3: FROM registry.access.redhat.com/ubi9/ubi:latest
    3. Trying to pull registry.access.redhat.com/ubi9/ubi:latest...
    4. Getting image source signatures
    5. Checking if image destination supports signatures
    6. Copying blob 1153e061da4e done |
    7. Copying config 8d2a8803cf done |
    8. Writing manifest to image destination
    9. Storing signatures
    10. STEP 2/3: RUN dnf install -y python39
    11. Updating Subscription Management repositories.
    12. Unable to read consumer identity
    13. This system is not registered with an entitlement server. You can use subscription-manager to register.
    14. Red Hat Universal Base Image 9 (RPMs) - BaseOS 118 kB/s | 515 kB 00:04
    15. Red Hat Universal Base Image 9 (RPMs) - AppStre 683 kB/s | 1.8 MB 00:02
    16. Red Hat Universal Base Image 9 (RPMs) - CodeRea 67 kB/s | 192 kB 00:02
    17. Package python3-3.9.18-1.el9_3.1.x86_64 is already installed.
    18. Dependencies resolved.
    19. Nothing to do.
    20. Complete!
    21. --> bf856a94a83f
    22. STEP 3/3: CMD ["/bin/bash","-c","sleep infinity"]
    23. COMMIT python39:1.0
    24. --> 0274d417a217
    25. Successfully tagged localhost/python39:1.0
    26. 0274d417a21704d9e66aec64b1a0f9934ae822e776704044523e12eb1db5063c

    查看镜像

    1. [root@service ~]# podman images
    2. REPOSITORY TAG IMAGE ID CREATED SIZE
    3. localhost/python39 1.0 0274d417a217 9 seconds ago 225 MB
    4. registry.access.redhat.com/ubi9/ubi latest 8d2a8803cfca 8 days ago 219 MB
    5. docker.io/library/python latest a3aef63c6c10 4 weeks ago 1.04 GB

    运行容器

    1. [root@service ~]# podman create --name python39 localhost/python39:1.0
    2. 2cf96e0ccbcbcceb66664cb5e93414e8f1f0163b44352c2f3b652ff2e95b9855
    3. [root@service ~]# podman ps
    4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    5. [root@service ~]# podman ps -a
    6. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    7. 2cf96e0ccbcb localhost/python39:1.0 /bin/bash -c slee... 9 seconds ago Created python39
    8. [root@service ~]# podman start python39
    9. python39
    10. [root@service ~]# podman ps
    11. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    12. 2cf96e0ccbcb localhost/python39:1.0 /bin/bash -c slee... 46 seconds ago Up 17 seconds python39

    删除容器

    1. [root@service ~]# podman stop python39
    2. WARN[0010] StopSignal SIGTERM failed to stop container python39 in 10 seconds, resorting to SIGKILL
    3. python39
    4. [root@service ~]# podman ps
    5. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    6. [root@service ~]# podman ps -a
    7. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    8. 2cf96e0ccbcb localhost/python39:1.0 /bin/bash -c slee... 2 minutes ago Exited (137) 32 seconds ago python39
    9. [root@service ~]# podman rm python39
    10. python39
    11. [root@service ~]# podman rmi localhost/python39:1.0
    12. Untagged: localhost/python39:1.0
    13. Deleted: 0274d417a21704d9e66aec64b1a0f9934ae822e776704044523e12eb1db5063c
    14. Deleted: bf856a94a83f1f433aa54190152d11556e24bb105876eb8342947358a420b203

  • 相关阅读:
    SpringCloud-06-Config
    牛客java训练题 day1
    国庆北京游玩攻略
    Go 程序打成 rpm 包
    Pisa-Proxy 之 SQL 解析实践
    高德地图通过画面中的一个覆盖物设置图中心点和zoom
    ai绘画软件哪个好用?这5个工具值得尝试
    HarmonyOS 实现底部导航栏
    FFmpeg 硬件加速介绍
    C++学习随笔(3)——auto和for
  • 原文地址:https://blog.csdn.net/m0_66011019/article/details/136589672