{"id":232824,"date":"2021-12-28T08:36:32","date_gmt":"2021-12-28T00:36:32","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=232824"},"modified":"2021-12-22T16:38:06","modified_gmt":"2021-12-22T08:38:06","slug":"build-podman-env","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/build-podman-env.html","title":{"rendered":"\u5982\u4f55\u5feb\u901f\u5efa\u7acb\u4e00\u4e2apodman\u73af\u5883"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u5b89\u88c5podman\uff0c\u5e76\u521b\u5efapodman\u5bb9\u5668<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u73af\u5883<\/strong><\/div>\n

Centos8<\/p>\n

\u5b89\u88c5podman<\/strong><\/div>\n

Podman \u662f\u4e00\u4e2a\u5bb9\u5668\u73af\u5883\uff0c\u9996\u5148\u5728\u4e3b\u673a\u4e0a\u5b89\u88c5 Podman\u3002\u6267\u884c\u4e0b\u9762\u547d\u4ee4\u6765\u5b89\u88c5podman\uff1a<\/p>\n

\r\n[root@localhost ~]# yum -y install podman\r\n<\/pre>\n

\u7136\u540e\u4fee\u6539\u4e00\u4e0b\u7528\u6237\u547d\u540d\u7a7a\u95f4\u7684\u5927\u5c0f\uff1a<\/p>\n

\r\n[root@localhost ~]# echo \"user.max_user_namespaces=28633\" >> \/etc\/sysctl.d\/userns.conf\r\n[root@localhost ~]# sysctl -p \/etc\/sysctl.d\/userns.conf\r\nuser.max_user_namespaces = 28633\r\n<\/pre>\n

\u4e0b\u9762\u521b\u5efa\u4e00\u4e2apodman\u5bb9\u5668\u6765\u770b\u4e00\u4e0b\u5427\uff0c\u4e0b\u9762\u4f7f\u7528\u7684\u662fRHEL\u7684UBI\u955c\u50cf\uff1a<\/p>\n

\r\n[root@localhost ~]# podman run ubi8\/ubi cat \/etc\/os-release\r\nResolved \"ubi8\/ubi\" as an alias (\/etc\/containers\/registries.conf.d\/001-rhel-shortnames.conf)\r\nTrying to pull registry.access.redhat.com\/ubi8\/ubi:latest...\r\nGetting image source signatures\r\nChecking if image destination supports signatures\r\nCopying blob ce3c6836540f done  \r\nCopying blob 63f9f4c31162 done  \r\nCopying config cc06568478 done  \r\nWriting manifest to image destination\r\nStoring signatures\r\nNAME=\"Red Hat Enterprise Linux\"\r\nVERSION=\"8.5 (Ootpa)\"\r\nID=\"rhel\"\r\nID_LIKE=\"fedora\"\r\nVERSION_ID=\"8.5\"\r\nPLATFORM_ID=\"platform:el8\"\r\nPRETTY_NAME=\"Red Hat Enterprise Linux 8.5 (Ootpa)\"\r\nANSI_COLOR=\"0;31\"\r\nCPE_NAME=\"cpe:\/o:redhat:enterprise_linux:8::baseos\"\r\nHOME_URL=\"https:\/\/www.redhat.com\/\"\r\nDOCUMENTATION_URL=\"https:\/\/access.redhat.com\/documentation\/red_hat_enterprise_linux\/8\/\"\r\nBUG_REPORT_URL=\"https:\/\/bugzilla.redhat.com\/\"\r\n\r\nREDHAT_BUGZILLA_PRODUCT=\"Red Hat Enterprise Linux 8\"\r\nREDHAT_BUGZILLA_PRODUCT_VERSION=8.5\r\nREDHAT_SUPPORT_PRODUCT=\"Red Hat Enterprise Linux\"\r\nREDHAT_SUPPORT_PRODUCT_VERSION=\"8.5\"\r\n<\/pre>\n

\"\"<\/p>\n

\u521b\u5efaDockerfile<\/strong><\/div>\n

\u73b0\u5728\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a Dockerfile \u6765\u6307\u5b9a\u5982\u4f55\u6784\u5efa\u65b0\u7684\u955c\u50cf\u3002\u9996\u5148\u9700\u8981\u4e3a Dockerfile \u6587\u4ef6\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55\uff1a<\/p>\n

\r\n[root@localhost ~]# mkdir ~\/myc\r\n[root@localhost ~]# cd ~\/myc\r\n<\/pre>\n

\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6Dockerfile\u6587\u4ef6\uff0c\u6765\u5efa\u7acb\u4e00\u4e2a\u65b0\u955c\u50cf\uff1a<\/p>\n

\r\n[root@localhost myc]# vim Dockerfile\r\n\r\nFROM ubi8\/ubi:latest\r\nRUN dnf install -y nano\r\n<\/pre>\n

\"\"
\n\u5f00\u59cb\u4f7f\u7528podman build\u6765\u521b\u5efa\u5bb9\u5668\uff1a<\/p>\n

\r\n[root@localhost myc]# podman build -f Dockerfile -t ubi-with-nano\r\n[root@localhost myc]# podman build -f Dockerfile -t ubi-with-nano\r\nSTEP 1\/2: FROM ubi8\/ubi:latest\r\nSTEP 2\/2: RUN dnf install -y nano\r\nUpdating Subscription Management repositories.\r\nUnable to read consumer identity\r\n...\r\n<\/pre>\n

\"\"
\n\u4f7f\u7528podman images<\/code>\u6765\u786e\u8ba4\u662f\u5426\u521b\u5efa\u65b0\u955c\u50cf\uff1a<\/p>\n

\r\n[root@localhost myc]# podman images\r\n<\/pre>\n

\"\"
\n\u73b0\u5728\u4f60\u53ef\u4ee5\u8fd0\u884c\u5bb9\u5668\u4e86\uff0c\u68c0\u67e5nano\u7f16\u8f91\u5668\u662f\u5426\u53ef\u7528\uff1a<\/p>\n

\r\n[root@localhost myc]# podman run localhost\/ubi-with-nano \/usr\/bin\/which nano\r\n\/usr\/bin\/nano\r\n<\/pre>\n

\u901a\u8fc7\u67e5\u770bnano\u6267\u884c\u6587\u4ef6\u7684\u4f4d\u7f6e\uff0c\u6765\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u3002<\/p>\n

Nano \u73b0\u5728\u5df2\u5b89\u88c5\u5728\u4f60\u7684\u81ea\u5b9a\u4e49\u5bb9\u5668\u4e2d\u3002\u8fd8\u53ef\u4ee5\u4ea4\u4e92\u5f0f\u7684\u8fd0\u884c\u5bb9\u5668\uff1a<\/p>\n

\r\n[root@localhost myc]# podman run -it localhost\/ubi-with-nano \/bin\/bash\r\n[root@d1f0e46f2b6d \/]# ls\r\nbin   dev  home  lib64      media  opt   root sbin  sys  usr\r\nboot  etc  lib  lost+found  mnt    proc  run srv   tmp  var\r\n[root@d1f0e46f2b6d \/]# \r\n<\/pre>\n

\"\"
\n\u5728\u5bb9\u5668\u4e2d\u8fd0\u884cexit<\/code>\u6765\u9000\u51fa\u5bb9\u5668\u3002<\/p>\n

\u53ef\u4ee5\u4f7f\u7528podman ps<\/code>\u6765\u67e5\u770b\u8fd0\u884c\u7684\u5bb9\u5668\uff0c\u5982\u679c\u9700\u8981\u67e5\u770b\u4ee5\u505c\u6b62\u7684\u5bb9\u5668\uff0c\u53ef\u4ee5\u6dfb\u52a0-a<\/code>\u9009\u9879\uff1a<\/p>\n

\r\n[root@localhost myc]# podman ps \r\n[root@localhost myc]# podman ps -a\r\n<\/pre>\n

\"\"<\/p>\n

\u5b58\u50a8<\/strong><\/div>\n

\u7ecf\u5e38\u8ba9\u65b0\u7528\u6237\u611f\u5230\u56f0\u60d1\u7684\u4e00\u4ef6\u4e8b\u662f\u5b83\u4eec\u7684\u77ed\u6682\u6027\u3002\u4f8b\u5982\u8fdb\u5165\u5bb9\u5668\u91cc\u521b\u5efa\u7684\u6587\u4ef6\uff0c\u9000\u51fa\u4e4b\u540e\uff0c\u518d\u6b21\u8fdb\u5165\u53d1\u73b0\u6587\u4ef6\u6ca1\u6709\u4e86\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u5bb9\u5668\u4e2d\u9700\u8981\u5b58\u50a8\u6c38\u4e45\u6027\u6587\u4ef6\u7684\u6587\u4ef6\u5939\u6302\u8f7d\u5230\u7cfb\u7edf\u7684\u67d0\u4e2a\u6587\u4ef6\u5939\u4e2d\u3002\u4e0b\u9762\u5728\u672c\u673a\u521b\u5efa\u4e00\u4e2a\u5b58\u50a8\u4f4d\u7f6e\uff1a<\/p>\n

\r\n[root@localhost ~]# mkdir \/pod_data\r\n<\/pre>\n

\u7136\u540e\u4f7f\u7528\u60a8\u7684\u5b58\u50a8\u76ee\u5f55\u4f5c\u4e3a\u4e00\u4e9b\u76f8\u5173\u7684\u6302\u8f7d\u70b9\u6765\u542f\u52a8\u5bb9\u5668\u3002\u6b64\u793a\u4f8b\u5c06\u672c\u5730\u76ee\u5f55\/pod_data<\/code>\u7ed1\u5b9a\u5230\u5bb9\u5668\u4e2d\u540d\u4e3a\/storage<\/code> \u7684\u4f4d\u7f6e\uff0c\u5fc5\u987b\u5728\u76ee\u5f55\u4f4d\u7f6e\u9644\u52a0 :Z<\/code>\uff0c\u4ee5\u4fbf SELinux \u53ef\u4ee5\u5728\u4e3b\u673a\u548c Podman \u4e4b\u95f4\u8f6c\u6362\u4e0a\u4e0b\u6587\u3002<\/p>\n

\r\n[root@localhost ~]# podman run -it --volume \/pod_data:\/storage:Z localhost\/ubi-with-nano\r\n[root@d590bc344b76 \/]# echo \"hello podman\" >> \/storage\/msg.txt\r\n[root@d590bc344b76 \/]# exit\r\nexit\r\n[root@localhost ~]# cat \/pod_data\/msg.txt \r\nhello podman\r\n<\/pre>\n

\"\"
\n\u53ef\u4ee5\u770b\u5230\u76ee\u5f55\u7ed1\u5b9a\u4e4b\u540e\uff0c\u5728\u5bb9\u5668\u4e2d\u5199\u5165\u6570\u636e\uff0c\u9000\u51fa\u5bb9\u5668\uff0c\u5728\u672c\u673a\u7684\/pod_data<\/code>\u53ef\u4ee5\u770b\u5230\u5199\u5165\u7684\u5185\u5bb9\u3002<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u5b89\u88c5podman\uff0c\u5e76\u521b\u5efapodman\u5bb9\u5668<\/p>\n","protected":false},"excerpt":{"rendered":"

Centos8 Podman \u662f\u4e00\u4e2a\u5bb9\u5668\u73af\u5883\uff0c\u9996\u5148\u5728\u4e3b\u673a\u4e0a\u5b89\u88c5 Podman\u3002\u6267\u884c\u4e0b\u9762\u547d\u4ee4\u6765\u5b89\u88c5podman\uff1a […]<\/p>\n","protected":false},"author":309,"featured_media":232825,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-232824","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/232824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=232824"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/232824\/revisions"}],"predecessor-version":[{"id":232834,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/232824\/revisions\/232834"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/232825"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=232824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=232824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=232824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}