• RHCSA 02 - 自启动rootless容器


    前言

    本文演示如何创建自启动rootless容器。

    什么是rootless容器?

    一般我们看到的容器,都是使用root账号启动。而rootless容器则指的是以非root账号启动的容器。

    实践

    步骤1:安装容器包

    1. [root@ad57f7d54660 ~]# dnf module install -y container-tools
    2. Rocky Linux 8 - AppStream 19 kB/s | 4.8 kB 00:00
    3. Rocky Linux 8 - AppStream 19 MB/s | 8.8 MB 00:00
    4. Rocky Linux 8 - BaseOS 18 kB/s | 4.3 kB 00:00
    5. Rocky Linux 8 - BaseOS 9.9 MB/s | 3.6 MB 00:00
    6. Rocky Linux 8 - Extras 16 kB/s | 3.5 kB 00:00
    7. Rocky Linux 8 - Extras 39 kB/s | 11 kB 00:00
    8. Dependencies resolved.
    9. ====================================================================================================
    10. Package Arch Version Repository Size
    11. ====================================================================================================
    12. Upgrading:
    13. audit x86_64 3.0.7-2.el8.2 baseos 262 k
    14. audit-libs x86_64 3.0.7-2.el8.2 baseos 122 k
    15. libsemanage x86_64 2.9-8.el8 baseos 167 k
    16. platform-python-pip noarch 9.0.3-22.el8.rocky.0 baseos 1.6 M
    17. policycoreutils x86_64 2.9-19.el8 baseos 373 k
    18. Installing group/module packages:
    19. buildah x86_64 1:1.24.2-4.module+el8.6.0+971+69b94baf appstream 8.0 M
    20. cockpit-podman noarch 43-1.module+el8.6.0+971+69b94baf appstream 492 k
    21. conmon x86_64 2:2.1.0-1.module+el8.6.0+971+69b94baf appstream 54 k
    22. container-selinux noarch 2:2.179.1-1.module+el8.6.0+971+69b94baf appstream 57 k
    23. containernetworking-plugins x86_64 1:1.0.1-2.module+el8.6.0+971+69b94baf appstream 18 M
    24. containers-common x86_64 2:1-27.module+el8.6.0+971+69b94baf appstream 95 k
    25. criu x86_64 3.15-3.module+el8.6.0+971+69b94baf appstream 517 k
    26. crun x86_64 1.4.4-1.module+el8.6.0+971+69b94baf appstream 208 k
    27. fuse-overlayfs x86_64 1.8.2-1.module+el8.6.0+971+69b94baf appstream 72 k
    28. libslirp x86_64 4.4.0-1.module+el8.6.0+971+69b94baf appstream 69 k
    29. podman x86_64 2:4.0.2-6.module+el8.6.0+971+69b94baf appstream 13 M
    30. python3-podman noarch 4.0.0-1.module+el8.6.0+785+d1251653 appstream 148 k
    31. runc x86_64 1:1.0.3-2.module+el8.6.0+971+69b94baf appstream 3.0 M
    32. skopeo x86_64 2:1.6.1-2.module+el8.6.0+971+69b94baf appstream 6.7 M
    33. slirp4netns x86_64 1.1.8-2.module+el8.6.0+971+69b94baf appstream 50 k
    34. toolbox x86_64 0.0.99.3-0.4.module+el8.6.0+971+69b94baf appstream 2.2 M
    35. udica noarch 0.2.6-3.module+el8.6.0+971+69b94baf appstream 48 k
    36. Installing dependencies:
    37. checkpolicy x86_64 2.9-1.el8 baseos 345 k
    38. cockpit-bridge x86_64 264.1-1.el8 baseos 533 k
    39. dejavu-fonts-common noarch 2.35-7.el8 baseos 73 k
    40. fontpackages-filesystem noarch 1.44-22.el8 baseos 15 k
    41. fuse-common x86_64 3.3.0-15.el8 baseos 21 k
    42. fuse3 x86_64 3.3.0-15.el8 baseos 53 k
    43. fuse3-libs x86_64 3.3.0-15.el8 baseos 94 k
    44. glib-networking x86_64 2.56.1-1.1.el8 baseos 153 k
    45. gsettings-desktop-schemas x86_64 3.32.0-6.el8 baseos 632 k
    46. json-glib x86_64 1.4.4-1.el8 baseos 143 k
    47. libmodman x86_64 2.0.1-17.el8 baseos 35 k
    48. libnet x86_64 1.1.6-15.el8 appstream 66 k
    49. libproxy x86_64 0.4.15-5.2.el8 baseos 73 k
    50. podman-catatonit x86_64 2:4.0.2-6.module+el8.6.0+971+69b94baf appstream 353 k
    51. policycoreutils-python-utils noarch 2.9-19.el8 baseos 252 k
    52. protobuf-c x86_64 1.3.0-6.el8 appstream 36 k
    53. python3-audit x86_64 3.0.7-2.el8.2 baseos 86 k
    54. python3-chardet noarch 3.0.4-7.el8 baseos 194 k
    55. python3-idna noarch 2.5-5.el8 baseos 96 k
    56. python3-libsemanage x86_64 2.9-8.el8 baseos 127 k
    57. python3-pip noarch 9.0.3-22.el8.rocky.0 appstream 19 k
    58. python3-policycoreutils noarch 2.9-19.el8 baseos 2.2 M
    59. python3-pysocks noarch 1.6.8-3.el8 baseos 33 k
    60. python3-pytoml noarch 0.1.14-5.git7dea353.el8 appstream 24 k
    61. python3-pyxdg noarch 0.25-16.el8 appstream 93 k
    62. python3-requests noarch 2.20.0-2.1.el8_1 baseos 122 k
    63. python3-setools x86_64 4.3.0-3.el8 baseos 623 k
    64. python3-setuptools noarch 39.2.0-6.el8 baseos 162 k
    65. python3-urllib3 noarch 1.24.2-5.el8 baseos 176 k
    66. python36 x86_64 3.6.8-38.module+el8.5.0+671+195e4563 appstream 18 k
    67. shadow-utils-subid x86_64 2:4.6-16.el8 baseos 111 k
    68. yajl x86_64 2.1.0-10.el8 appstream 40 k
    69. Installing weak dependencies:
    70. abattis-cantarell-fonts noarch 0.0.25-6.el8 appstream 154 k
    71. dejavu-sans-mono-fonts noarch 2.35-7.el8 baseos 446 k
    72. tar x86_64 2:1.30-5.el8 baseos 837 k
    73. Installing module profiles:
    74. container-tools/common
    75. Enabling module streams:
    76. container-tools rhel8
    77. python36 3.6
    78. Transaction Summary
    79. ====================================================================================================
    80. Install 52 Packages
    81. Upgrade 5 Packages
    82. Total download size: 64 M
    83. Downloading Packages:
    84. (1/57): abattis-cantarell-fonts-0.0.25-6.el8.noarch.rpm 2.0 MB/s | 154 kB 00:00 A
    85. (2/57): conmon-2.1.0-1.module+el8.6.0+971+69b94baf.x86_64.rpm 3.6 MB/s | 54 kB 00:00
    86. (3/57): cockpit-podman-43-1.module+el8.6.0+971+69b94baf.noarch.rpm 4.8 MB/s | 492 kB 00:00
    87. (4/57): container-selinux-2.179.1-1.module+el8.6.0+971+69b94baf.noa 5.8 MB/s | 57 kB 00:00
    88. (5/57): containers-common-1-27.module+el8.6.0+971+69b94baf.x86_64.r 12 MB/s | 95 kB 00:00
    89. (6/57): criu-3.15-3.module+el8.6.0+971+69b94baf.x86_64.rpm 25 MB/s | 517 kB 00:00
    90. (7/57): crun-1.4.4-1.module+el8.6.0+971+69b94baf.x86_64.rpm 21 MB/s | 208 kB 00:00
    91. (8/57): fuse-overlayfs-1.8.2-1.module+el8.6.0+971+69b94baf.x86_64.r 11 MB/s | 72 kB 00:00
    92. (9/57): libnet-1.1.6-15.el8.x86_64.rpm 11 MB/s | 66 kB 00:00
    93. (10/57): libslirp-4.4.0-1.module+el8.6.0+971+69b94baf.x86_64.rpm 11 MB/s | 69 kB 00:00
    94. (11/57): buildah-1.24.2-4.module+el8.6.0+971+69b94baf.x86_64.rpm 24 MB/s | 8.0 MB 00:00
    95. (12/57): podman-catatonit-4.0.2-6.module+el8.6.0+971+69b94baf.x86_6 21 MB/s | 353 kB 00:00
    96. (13/57): protobuf-c-1.3.0-6.el8.x86_64.rpm 9.3 MB/s | 36 kB 00:00
    97. (14/57): python3-pip-9.0.3-22.el8.rocky.0.noarch.rpm 4.9 MB/s | 19 kB 00:00
    98. (15/57): python3-podman-4.0.0-1.module+el8.6.0+785+d1251653.noarch. 16 MB/s | 148 kB 00:00
    99. (16/57): python3-pytoml-0.1.14-5.git7dea353.el8.noarch.rpm 4.4 MB/s | 24 kB 00:00
    100. (17/57): python3-pyxdg-0.25-16.el8.noarch.rpm 18 MB/s | 93 kB 00:00
    101. (18/57): python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64.rpm 5.0 MB/s | 18 kB 00:00
    102. (19/57): runc-1.0.3-2.module+el8.6.0+971+69b94baf.x86_64.rpm 32 MB/s | 3.0 MB 00:00
    103. (20/57): podman-4.0.2-6.module+el8.6.0+971+69b94baf.x86_64.rpm 33 MB/s | 13 MB 00:00
    104. (21/57): slirp4netns-1.1.8-2.module+el8.6.0+971+69b94baf.x86_64.rpm 7.1 MB/s | 50 kB 00:00
    105. (22/57): toolbox-0.0.99.3-0.4.module+el8.6.0+971+69b94baf.x86_64.rp 23 MB/s | 2.2 MB 00:00
    106. (23/57): udica-0.2.6-3.module+el8.6.0+971+69b94baf.noarch.rpm 4.8 MB/s | 48 kB 00:00
    107. (24/57): yajl-2.1.0-10.el8.x86_64.rpm 7.0 MB/s | 40 kB 00:00
    108. (25/57): checkpolicy-2.9-1.el8.x86_64.rpm 33 MB/s | 345 kB 00:00
    109. (26/57): cockpit-bridge-264.1-1.el8.x86_64.rpm 42 MB/s | 533 kB 00:00
    110. (27/57): skopeo-1.6.1-2.module+el8.6.0+971+69b94baf.x86_64.rpm 26 MB/s | 6.7 MB 00:00
    111. (28/57): dejavu-fonts-common-2.35-7.el8.noarch.rpm 2.3 MB/s | 73 kB 00:00
    112. (29/57): fontpackages-filesystem-1.44-22.el8.noarch.rpm 3.1 MB/s | 15 kB 00:00
    113. (30/57): fuse-common-3.3.0-15.el8.x86_64.rpm 4.9 MB/s | 21 kB 00:00
    114. (31/57): dejavu-sans-mono-fonts-2.35-7.el8.noarch.rpm 23 MB/s | 446 kB 00:00
    115. (32/57): fuse3-3.3.0-15.el8.x86_64.rpm 7.1 MB/s | 53 kB 00:00
    116. (33/57): fuse3-libs-3.3.0-15.el8.x86_64.rpm 15 MB/s | 94 kB 00:00
    117. (34/57): glib-networking-2.56.1-1.1.el8.x86_64.rpm 16 MB/s | 153 kB 00:00
    118. (35/57): json-glib-1.4.4-1.el8.x86_64.rpm 18 MB/s | 143 kB 00:00
    119. (36/57): gsettings-desktop-schemas-3.32.0-6.el8.x86_64.rpm 34 MB/s | 632 kB 00:00
    120. (37/57): libmodman-2.0.1-17.el8.x86_64.rpm 5.2 MB/s | 35 kB 00:00
    121. (38/57): libproxy-0.4.15-5.2.el8.x86_64.rpm 16 MB/s | 73 kB 00:00
    122. (39/57): policycoreutils-python-utils-2.9-19.el8.noarch.rpm 32 MB/s | 252 kB 00:00
    123. (40/57): python3-audit-3.0.7-2.el8.2.x86_64.rpm 9.3 MB/s | 86 kB 00:00
    124. (41/57): python3-chardet-3.0.4-7.el8.noarch.rpm 21 MB/s | 194 kB 00:00
    125. (42/57): python3-idna-2.5-5.el8.noarch.rpm 10 MB/s | 96 kB 00:00
    126. (43/57): python3-libsemanage-2.9-8.el8.x86_64.rpm 14 MB/s | 127 kB 00:00
    127. (44/57): python3-pysocks-1.6.8-3.el8.noarch.rpm 6.6 MB/s | 33 kB 00:00
    128. (45/57): containernetworking-plugins-1.0.1-2.module+el8.6.0+971+69b 24 MB/s | 18 MB 00:00
    129. (46/57): python3-requests-2.20.0-2.1.el8_1.noarch.rpm 1.9 MB/s | 122 kB 00:00
    130. (47/57): python3-setuptools-39.2.0-6.el8.noarch.rpm 9.6 MB/s | 162 kB 00:00
    131. (48/57): python3-urllib3-1.24.2-5.el8.noarch.rpm 16 MB/s | 176 kB 00:00
    132. (49/57): python3-setools-4.3.0-3.el8.x86_64.rpm 11 MB/s | 623 kB 00:00
    133. (50/57): shadow-utils-subid-4.6-16.el8.x86_64.rpm 3.6 MB/s | 111 kB 00:00
    134. (51/57): tar-1.30-5.el8.x86_64.rpm 22 MB/s | 837 kB 00:00
    135. (52/57): audit-libs-3.0.7-2.el8.2.x86_64.rpm 14 MB/s | 122 kB 00:00
    136. (53/57): python3-policycoreutils-2.9-19.el8.noarch.rpm 12 MB/s | 2.2 MB 00:00
    137. (54/57): audit-3.0.7-2.el8.2.x86_64.rpm 3.3 MB/s | 262 kB 00:00
    138. (55/57): libsemanage-2.9-8.el8.x86_64.rpm 4.3 MB/s | 167 kB 00:00
    139. (56/57): policycoreutils-2.9-19.el8.x86_64.rpm 23 MB/s | 373 kB 00:00
    140. (57/57): platform-python-pip-9.0.3-22.el8.rocky.0.noarch.rpm 31 MB/s | 1.6 MB 00:00
    141. ----------------------------------------------------------------------------------------------------
    142. Total 45 MB/s | 64 MB 00:01
    143. Running transaction check
    144. Transaction check succeeded.
    145. Running transaction test
    146. Transaction test succeeded.
    147. Running transaction
    148. Preparing : 1/1
    149. Running scriptlet: audit-libs-3.0.7-2.el8.2.x86_64 1/1
    150. Upgrading : audit-libs-3.0.7-2.el8.2.x86_64 1/62
    151. Upgrading : libsemanage-2.9-8.el8.x86_64 2/62
    152. Installing : python3-libsemanage-2.9-8.el8.x86_64 3/62
    153. Upgrading : policycoreutils-2.9-19.el8.x86_64 4/62
    154. Running scriptlet: policycoreutils-2.9-19.el8.x86_64 4/62
    155. Installing : fuse3-libs-3.3.0-15.el8.x86_64 5/62
    156. Running scriptlet: fuse3-libs-3.3.0-15.el8.x86_64 5/62
    157. Installing : fontpackages-filesystem-1.44-22.el8.noarch 6/62
    158. Installing : abattis-cantarell-fonts-0.0.25-6.el8.noarch 7/62
    159. Installing : dejavu-fonts-common-2.35-7.el8.noarch 8/62
    160. Installing : dejavu-sans-mono-fonts-2.35-7.el8.noarch 9/62
    161. Installing : gsettings-desktop-schemas-3.32.0-6.el8.x86_64 10/62
    162. Installing : shadow-utils-subid-2:4.6-16.el8.x86_64 11/62
    163. Installing : python3-audit-3.0.7-2.el8.2.x86_64 12/62
    164. Upgrading : platform-python-pip-9.0.3-22.el8.rocky.0.noarch 13/62
    165. Installing : tar-2:1.30-5.el8.x86_64 14/62
    166. Running scriptlet: tar-2:1.30-5.el8.x86_64 14/62
    167. Installing : python3-setuptools-39.2.0-6.el8.noarch 15/62
    168. Installing : python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64 16/62
    169. Running scriptlet: python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64 16/62
    170. Installing : python3-pip-9.0.3-22.el8.rocky.0.noarch 17/62
    171. Installing : python3-setools-4.3.0-3.el8.x86_64 18/62
    172. Installing : python3-pysocks-1.6.8-3.el8.noarch 19/62
    173. Installing : python3-urllib3-1.24.2-5.el8.noarch 20/62
    174. Installing : python3-idna-2.5-5.el8.noarch 21/62
    175. Installing : python3-chardet-3.0.4-7.el8.noarch 22/62
    176. Installing : python3-requests-2.20.0-2.1.el8_1.noarch 23/62
    177. Installing : libmodman-2.0.1-17.el8.x86_64 24/62
    178. Running scriptlet: libmodman-2.0.1-17.el8.x86_64 24/62
    179. Installing : libproxy-0.4.15-5.2.el8.x86_64 25/62
    180. Running scriptlet: libproxy-0.4.15-5.2.el8.x86_64 25/62
    181. Installing : glib-networking-2.56.1-1.1.el8.x86_64 26/62
    182. Installing : json-glib-1.4.4-1.el8.x86_64 27/62
    183. Installing : cockpit-bridge-264.1-1.el8.x86_64 28/62
    184. Installing : fuse-common-3.3.0-15.el8.x86_64 29/62
    185. Installing : fuse3-3.3.0-15.el8.x86_64 30/62
    186. Installing : fuse-overlayfs-1.8.2-1.module+el8.6.0+971+69b94baf.x86_64 31/62
    187. Running scriptlet: fuse-overlayfs-1.8.2-1.module+el8.6.0+971+69b94baf.x86_64 31/62
    188. Installing : checkpolicy-2.9-1.el8.x86_64 32/62
    189. Installing : python3-policycoreutils-2.9-19.el8.noarch 33/62
    190. Installing : policycoreutils-python-utils-2.9-19.el8.noarch 34/62
    191. Running scriptlet: container-selinux-2:2.179.1-1.module+el8.6.0+971+69b94baf.noarch 35/62
    192. Installing : container-selinux-2:2.179.1-1.module+el8.6.0+971+69b94baf.noarch 35/62
    193. Running scriptlet: container-selinux-2:2.179.1-1.module+el8.6.0+971+69b94baf.noarch 35/62
    194. Installing : yajl-2.1.0-10.el8.x86_64 36/62
    195. Installing : crun-1.4.4-1.module+el8.6.0+971+69b94baf.x86_64 37/62
    196. Installing : python3-pyxdg-0.25-16.el8.noarch 38/62
    197. Installing : python3-pytoml-0.1.14-5.git7dea353.el8.noarch 39/62
    198. Installing : protobuf-c-1.3.0-6.el8.x86_64 40/62
    199. Installing : libslirp-4.4.0-1.module+el8.6.0+971+69b94baf.x86_64 41/62
    200. Installing : slirp4netns-1.1.8-2.module+el8.6.0+971+69b94baf.x86_64 42/62
    201. Installing : libnet-1.1.6-15.el8.x86_64 43/62
    202. Running scriptlet: libnet-1.1.6-15.el8.x86_64 43/62
    203. Installing : criu-3.15-3.module+el8.6.0+971+69b94baf.x86_64 44/62
    204. Installing : runc-1:1.0.3-2.module+el8.6.0+971+69b94baf.x86_64 45/62
    205. Installing : containers-common-2:1-27.module+el8.6.0+971+69b94baf.x86_64 46/62
    206. Installing : containernetworking-plugins-1:1.0.1-2.module+el8.6.0+971+69b94baf.x86_ 47/62
    207. Installing : conmon-2:2.1.0-1.module+el8.6.0+971+69b94baf.x86_64 48/62
    208. Installing : podman-catatonit-2:4.0.2-6.module+el8.6.0+971+69b94baf.x86_64 49/62
    209. Installing : podman-2:4.0.2-6.module+el8.6.0+971+69b94baf.x86_64 50/62
    210. Installing : cockpit-podman-43-1.module+el8.6.0+971+69b94baf.noarch 51/62
    211. Installing : toolbox-0.0.99.3-0.4.module+el8.6.0+971+69b94baf.x86_64 52/62
    212. Installing : buildah-1:1.24.2-4.module+el8.6.0+971+69b94baf.x86_64 53/62
    213. Installing : skopeo-2:1.6.1-2.module+el8.6.0+971+69b94baf.x86_64 54/62
    214. Installing : python3-podman-4.0.0-1.module+el8.6.0+785+d1251653.noarch 55/62
    215. Installing : udica-0.2.6-3.module+el8.6.0+971+69b94baf.noarch 56/62
    216. Upgrading : audit-3.0.7-2.el8.2.x86_64 57/62
    217. Running scriptlet: audit-3.0.7-2.el8.2.x86_64 57/62
    218. Running scriptlet: policycoreutils-2.9-16.el8.x86_64 58/62
    219. Cleanup : policycoreutils-2.9-16.el8.x86_64 58/62
    220. Running scriptlet: audit-3.0-0.17.20191104git1c2f876.el8.1.x86_64 59/62
    221. Cleanup : audit-3.0-0.17.20191104git1c2f876.el8.1.x86_64 59/62
    222. Running scriptlet: audit-3.0-0.17.20191104git1c2f876.el8.1.x86_64 59/62
    223. Cleanup : platform-python-pip-9.0.3-20.el8.rocky.0.noarch 60/62
    224. Cleanup : libsemanage-2.9-6.el8.x86_64 61/62
    225. Cleanup : audit-libs-3.0-0.17.20191104git1c2f876.el8.1.x86_64 62/62
    226. Running scriptlet: container-selinux-2:2.179.1-1.module+el8.6.0+971+69b94baf.noarch 62/62
    227. Running scriptlet: audit-libs-3.0-0.17.20191104git1c2f876.el8.1.x86_64 62/62
    228. Verifying : abattis-cantarell-fonts-0.0.25-6.el8.noarch 1/62
    229. Verifying : buildah-1:1.24.2-4.module+el8.6.0+971+69b94baf.x86_64 2/62
    230. Verifying : cockpit-podman-43-1.module+el8.6.0+971+69b94baf.noarch 3/62
    231. Verifying : conmon-2:2.1.0-1.module+el8.6.0+971+69b94baf.x86_64 4/62
    232. Verifying : container-selinux-2:2.179.1-1.module+el8.6.0+971+69b94baf.noarch 5/62
    233. Verifying : containernetworking-plugins-1:1.0.1-2.module+el8.6.0+971+69b94baf.x86_ 6/62
    234. Verifying : containers-common-2:1-27.module+el8.6.0+971+69b94baf.x86_64 7/62
    235. Verifying : criu-3.15-3.module+el8.6.0+971+69b94baf.x86_64 8/62
    236. Verifying : crun-1.4.4-1.module+el8.6.0+971+69b94baf.x86_64 9/62
    237. Verifying : fuse-overlayfs-1.8.2-1.module+el8.6.0+971+69b94baf.x86_64 10/62
    238. Verifying : libnet-1.1.6-15.el8.x86_64 11/62
    239. Verifying : libslirp-4.4.0-1.module+el8.6.0+971+69b94baf.x86_64 12/62
    240. Verifying : podman-2:4.0.2-6.module+el8.6.0+971+69b94baf.x86_64 13/62
    241. Verifying : podman-catatonit-2:4.0.2-6.module+el8.6.0+971+69b94baf.x86_64 14/62
    242. Verifying : protobuf-c-1.3.0-6.el8.x86_64 15/62
    243. Verifying : python3-pip-9.0.3-22.el8.rocky.0.noarch 16/62
    244. Verifying : python3-podman-4.0.0-1.module+el8.6.0+785+d1251653.noarch 17/62
    245. Verifying : python3-pytoml-0.1.14-5.git7dea353.el8.noarch 18/62
    246. Verifying : python3-pyxdg-0.25-16.el8.noarch 19/62
    247. Verifying : python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64 20/62
    248. Verifying : runc-1:1.0.3-2.module+el8.6.0+971+69b94baf.x86_64 21/62
    249. Verifying : skopeo-2:1.6.1-2.module+el8.6.0+971+69b94baf.x86_64 22/62
    250. Verifying : slirp4netns-1.1.8-2.module+el8.6.0+971+69b94baf.x86_64 23/62
    251. Verifying : toolbox-0.0.99.3-0.4.module+el8.6.0+971+69b94baf.x86_64 24/62
    252. Verifying : udica-0.2.6-3.module+el8.6.0+971+69b94baf.noarch 25/62
    253. Verifying : yajl-2.1.0-10.el8.x86_64 26/62
    254. Verifying : checkpolicy-2.9-1.el8.x86_64 27/62
    255. Verifying : cockpit-bridge-264.1-1.el8.x86_64 28/62
    256. Verifying : dejavu-fonts-common-2.35-7.el8.noarch 29/62
    257. Verifying : dejavu-sans-mono-fonts-2.35-7.el8.noarch 30/62
    258. Verifying : fontpackages-filesystem-1.44-22.el8.noarch 31/62
    259. Verifying : fuse-common-3.3.0-15.el8.x86_64 32/62
    260. Verifying : fuse3-3.3.0-15.el8.x86_64 33/62
    261. Verifying : fuse3-libs-3.3.0-15.el8.x86_64 34/62
    262. Verifying : glib-networking-2.56.1-1.1.el8.x86_64 35/62
    263. Verifying : gsettings-desktop-schemas-3.32.0-6.el8.x86_64 36/62
    264. Verifying : json-glib-1.4.4-1.el8.x86_64 37/62
    265. Verifying : libmodman-2.0.1-17.el8.x86_64 38/62
    266. Verifying : libproxy-0.4.15-5.2.el8.x86_64 39/62
    267. Verifying : policycoreutils-python-utils-2.9-19.el8.noarch 40/62
    268. Verifying : python3-audit-3.0.7-2.el8.2.x86_64 41/62
    269. Verifying : python3-chardet-3.0.4-7.el8.noarch 42/62
    270. Verifying : python3-idna-2.5-5.el8.noarch 43/62
    271. Verifying : python3-libsemanage-2.9-8.el8.x86_64 44/62
    272. Verifying : python3-policycoreutils-2.9-19.el8.noarch 45/62
    273. Verifying : python3-pysocks-1.6.8-3.el8.noarch 46/62
    274. Verifying : python3-requests-2.20.0-2.1.el8_1.noarch 47/62
    275. Verifying : python3-setools-4.3.0-3.el8.x86_64 48/62
    276. Verifying : python3-setuptools-39.2.0-6.el8.noarch 49/62
    277. Verifying : python3-urllib3-1.24.2-5.el8.noarch 50/62
    278. Verifying : shadow-utils-subid-2:4.6-16.el8.x86_64 51/62
    279. Verifying : tar-2:1.30-5.el8.x86_64 52/62
    280. Verifying : audit-3.0.7-2.el8.2.x86_64 53/62
    281. Verifying : audit-3.0-0.17.20191104git1c2f876.el8.1.x86_64 54/62
    282. Verifying : audit-libs-3.0.7-2.el8.2.x86_64 55/62
    283. Verifying : audit-libs-3.0-0.17.20191104git1c2f876.el8.1.x86_64 56/62
    284. Verifying : libsemanage-2.9-8.el8.x86_64 57/62
    285. Verifying : libsemanage-2.9-6.el8.x86_64 58/62
    286. Verifying : platform-python-pip-9.0.3-22.el8.rocky.0.noarch 59/62
    287. Verifying : platform-python-pip-9.0.3-20.el8.rocky.0.noarch 60/62
    288. Verifying : policycoreutils-2.9-19.el8.x86_64 61/62
    289. Verifying : policycoreutils-2.9-16.el8.x86_64 62/62
    290. Upgraded:
    291. audit-3.0.7-2.el8.2.x86_64 audit-libs-3.0.7-2.el8.2.x86_64
    292. libsemanage-2.9-8.el8.x86_64 platform-python-pip-9.0.3-22.el8.rocky.0.noarch
    293. policycoreutils-2.9-19.el8.x86_64
    294. Installed:
    295. abattis-cantarell-fonts-0.0.25-6.el8.noarch
    296. buildah-1:1.24.2-4.module+el8.6.0+971+69b94baf.x86_64
    297. checkpolicy-2.9-1.el8.x86_64
    298. cockpit-bridge-264.1-1.el8.x86_64
    299. cockpit-podman-43-1.module+el8.6.0+971+69b94baf.noarch
    300. conmon-2:2.1.0-1.module+el8.6.0+971+69b94baf.x86_64
    301. container-selinux-2:2.179.1-1.module+el8.6.0+971+69b94baf.noarch
    302. containernetworking-plugins-1:1.0.1-2.module+el8.6.0+971+69b94baf.x86_64
    303. containers-common-2:1-27.module+el8.6.0+971+69b94baf.x86_64
    304. criu-3.15-3.module+el8.6.0+971+69b94baf.x86_64
    305. crun-1.4.4-1.module+el8.6.0+971+69b94baf.x86_64
    306. dejavu-fonts-common-2.35-7.el8.noarch
    307. dejavu-sans-mono-fonts-2.35-7.el8.noarch
    308. fontpackages-filesystem-1.44-22.el8.noarch
    309. fuse-common-3.3.0-15.el8.x86_64
    310. fuse-overlayfs-1.8.2-1.module+el8.6.0+971+69b94baf.x86_64
    311. fuse3-3.3.0-15.el8.x86_64
    312. fuse3-libs-3.3.0-15.el8.x86_64
    313. glib-networking-2.56.1-1.1.el8.x86_64
    314. gsettings-desktop-schemas-3.32.0-6.el8.x86_64
    315. json-glib-1.4.4-1.el8.x86_64
    316. libmodman-2.0.1-17.el8.x86_64
    317. libnet-1.1.6-15.el8.x86_64
    318. libproxy-0.4.15-5.2.el8.x86_64
    319. libslirp-4.4.0-1.module+el8.6.0+971+69b94baf.x86_64
    320. podman-2:4.0.2-6.module+el8.6.0+971+69b94baf.x86_64
    321. podman-catatonit-2:4.0.2-6.module+el8.6.0+971+69b94baf.x86_64
    322. policycoreutils-python-utils-2.9-19.el8.noarch
    323. protobuf-c-1.3.0-6.el8.x86_64
    324. python3-audit-3.0.7-2.el8.2.x86_64
    325. python3-chardet-3.0.4-7.el8.noarch
    326. python3-idna-2.5-5.el8.noarch
    327. python3-libsemanage-2.9-8.el8.x86_64
    328. python3-pip-9.0.3-22.el8.rocky.0.noarch
    329. python3-podman-4.0.0-1.module+el8.6.0+785+d1251653.noarch
    330. python3-policycoreutils-2.9-19.el8.noarch
    331. python3-pysocks-1.6.8-3.el8.noarch
    332. python3-pytoml-0.1.14-5.git7dea353.el8.noarch
    333. python3-pyxdg-0.25-16.el8.noarch
    334. python3-requests-2.20.0-2.1.el8_1.noarch
    335. python3-setools-4.3.0-3.el8.x86_64
    336. python3-setuptools-39.2.0-6.el8.noarch
    337. python3-urllib3-1.24.2-5.el8.noarch
    338. python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64
    339. runc-1:1.0.3-2.module+el8.6.0+971+69b94baf.x86_64
    340. shadow-utils-subid-2:4.6-16.el8.x86_64
    341. skopeo-2:1.6.1-2.module+el8.6.0+971+69b94baf.x86_64
    342. slirp4netns-1.1.8-2.module+el8.6.0+971+69b94baf.x86_64
    343. tar-2:1.30-5.el8.x86_64
    344. toolbox-0.0.99.3-0.4.module+el8.6.0+971+69b94baf.x86_64
    345. udica-0.2.6-3.module+el8.6.0+971+69b94baf.noarch
    346. yajl-2.1.0-10.el8.x86_64
    347. Complete!

    步骤2:创建普通用户wanlinwang,

    1. [root@55a87a3acb63 ~]# useradd wanlinwang
    2. [root@55a87a3acb63 ~]# echo password | passwd --stdin wanlinwang
    3. Changing password for user wanlinwang.
    4. passwd: all authentication tokens updated successfully.

    步骤3:打开linger特性。linger是允许用户在logout情况下可以跑long-running的服务。

    1. [root@55a87a3acb63 ~]# loginctl enable-linger wanlinwang
    2. [root@55a87a3acb63 ~]# loginctl show-user wanlinwang
    3. UID=1001
    4. GID=1001
    5. Name=wanlinwang
    6. Timestamp=Sat 2022-07-02 01:32:28 CEST
    7. TimestampMonotonic=355372762
    8. RuntimePath=/run/user/1001
    9. Service=user@1001.service
    10. Slice=user-1001.slice
    11. State=lingering
    12. Sessions=
    13. IdleHint=yes
    14. IdleSinceHint=0
    15. IdleSinceHintMonotonic=0
    16. Linger=yes

    步骤4:以wanlinwang登录本机,

    1. [root@55a87a3acb63 ~]# ssh wanlinwang@localhost
    2. The authenticity of host 'localhost (::1)' can't be established.
    3. ECDSA key fingerprint is SHA256:QlT07D/gCNOvYRiBlg/nXA6mtsMxbJjBOGlwyVqr8F0.
    4. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    5. Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
    6. wanlinwang@localhost's password:
    7. [wanlinwang@55a87a3acb63 ~]$

    步骤5:在wanlinwang的terminal,运行一个容器,

    1. [wanlinwang@55a87a3acb63 ~]$ podman run -d --name mynginx -p 8081:80 docker.io/library/nginx
    2. Trying to pull docker.io/library/nginx:latest...
    3. Getting image source signatures
    4. Copying blob fe0ef4c895f5 done
    5. Copying blob 8f46223e4234 done
    6. Copying blob b85a868b505f done
    7. Copying blob f4407ba1f103 done
    8. Copying blob 4a7307612456 done
    9. Copying blob 935cecace2a0 done
    10. Copying config 55f4b40fe4 done
    11. Writing manifest to image destination
    12. Storing signatures
    13. 2ae92bd97141cf76605d5a798a6938fe93676485b8d550927aaffe11a93ea551
    14. [wanlinwang@55a87a3acb63 ~]$ podman ps
    15. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    16. 2ae92bd97141 docker.io/library/nginx:latest nginx -g daemon o... 4 seconds ago Up 4 seconds ago 0.0.0.0:8081->80/tcp mynginx
    17. [wanlinwang@55a87a3acb63 ~]$

    从以上来看,成功以非root用户运行一个容器!接下来,我们看下如何让其自启动。

    步骤6:创建服务文件,

    1. [wanlinwang@55a87a3acb63 ~]$ mkdir -p ~/.config/systemd/user
    2. [wanlinwang@55a87a3acb63 ~]$ cd ~/.config/systemd/user
    3. [wanlinwang@55a87a3acb63 user]$ podman generate systemd --name mynginx --files
    4. /home/wanlinwang/.config/systemd/user/container-mynginx.service
    5. [wanlinwang@55a87a3acb63 user]$ cat container-mynginx.service
    6. # container-mynginx.service
    7. # autogenerated by Podman 4.0.2
    8. # Sat Jul 2 01:35:55 CEST 2022
    9. [Unit]
    10. Description=Podman container-mynginx.service
    11. Documentation=man:podman-generate-systemd(1)
    12. Wants=network-online.target
    13. After=network-online.target
    14. RequiresMountsFor=/run/user/1001/containers
    15. [Service]
    16. Environment=PODMAN_SYSTEMD_UNIT=%n
    17. Restart=on-failure
    18. TimeoutStopSec=70
    19. ExecStart=/usr/bin/podman start mynginx
    20. ExecStop=/usr/bin/podman stop -t 10 mynginx
    21. ExecStopPost=/usr/bin/podman stop -t 10 mynginx
    22. PIDFile=/run/user/1001/containers/overlay-containers/2ae92bd97141cf76605d5a798a6938fe93676485b8d550927aaffe11a93ea551/userdata/conmon.pid
    23. Type=forking
    24. [Install]
    25. WantedBy=default.target
    26. [wanlinwang@55a87a3acb63 user]$

    步骤7:reload服务文件,

    [wanlinwang@55a87a3acb63 user]$ systemctl --user daemon-reload

    步骤8:停止当前运行的容器,

    1. [wanlinwang@55a87a3acb63 user]$ podman stop mynginx
    2. mynginx

    步骤9:打开开机自启动,

    1. [wanlinwang@55a87a3acb63 user]$ systemctl --user enable --now container-mynginx.service
    2. Created symlink /home/wanlinwang/.config/systemd/user/default.target.wants/container-mynginx.service → /home/wanlinwang/.config/systemd/user/container-mynginx.service.
    3. [wanlinwang@55a87a3acb63 user]$ systemctl --user status container-mynginx.service
    4. ● container-mynginx.service - Podman container-mynginx.service
    5. Loaded: loaded (/home/wanlinwang/.config/systemd/user/container-mynginx.service; enabled; vendor preset: enabled)
    6. Active: active (running) since Sat 2022-07-02 01:38:01 CEST; 18s ago
    7. Docs: man:podman-generate-systemd(1)
    8. Process: 13340 ExecStart=/usr/bin/podman start mynginx (code=exited, status=0/SUCCESS)
    9. Main PID: 13367 (conmon)
    10. CGroup: /user.slice/user-1001.slice/user@1001.service/container-mynginx.service
    11. ├─13351 /usr/bin/slirp4netns --disable-host-loopback --mtu=65520 --enable-sandbox --enable-seccomp --ena>
    12. ├─13353 rootlessport
    13. ├─13358 rootlessport-child
    14. ├─13367 /usr/bin/conmon --api-version 1 -c 2ae92bd97141cf76605d5a798a6938fe93676485b8d550927aaffe11a93ea>
    15. └─2ae92bd97141cf76605d5a798a6938fe93676485b8d550927aaffe11a93ea551
    16. ├─13378 nginx: master process nginx -g daemon off;
    17. ├─13406 nginx: worker process
    18. └─13407 nginx: worker process
    19. [wanlinwang@55a87a3acb63 user]$ podman ps
    20. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    21. 2ae92bd97141 docker.io/library/nginx:latest nginx -g daemon o... 4 minutes ago Up 37 seconds ago 0.0.0.0:8081->80/tcp mynginx

    参考资料

    man loginctl手册

  • 相关阅读:
    python使用memory_profiler分析代码运行内存占用
    项目实战——Web自动化测试
    docker 安装minio 一脚shell脚本
    [机缘参悟-52]:交浅言深要因人而异
    dumpsys meminfo 详解
    React重新渲染指南
    智慧公厕管理系统:科技赋能城市公共卫生服务的便利
    网络安全笔记 -- RCE代码及命令执行漏洞
    antd4 icon使用svg
    正版授权 | DaisyDisk 4 Mac 磁盘数据分析清理工具软件
  • 原文地址:https://blog.csdn.net/thesre/article/details/125568489