{"id":234461,"date":"2022-01-30T08:54:54","date_gmt":"2022-01-30T00:54:54","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=234461"},"modified":"2022-01-21T09:55:49","modified_gmt":"2022-01-21T01:55:49","slug":"sudo-podman-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/sudo-podman-linux.html","title":{"rendered":"\u65e0\u9700sudo\u4f7f\u7528Podman\u5728Linux\u4e0a\u8fd0\u884c\u5bb9\u5668"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5bb9\u5668\u662f\u73b0\u4ee3\u8ba1\u7b97\u7684\u4e00\u4e2a\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u968f\u7740\u56f4\u7ed5\u5bb9\u5668\u7684\u57fa\u7840\u8bbe\u65bd\u7684\u53d1\u5c55\uff0c\u65b0\u7684\u548c\u66f4\u597d\u7684\u5de5\u5177\u5f00\u59cb\u6d6e\u51fa\u6c34\u9762\u3002\u8fc7\u53bb\uff0c\u4f60\u53ea\u9700\u7528 \u200b\u200bLXC\u200b\u200b\u200b \u5c31\u53ef\u4ee5\u8fd0\u884c\u5bb9\u5668\uff0c\u7136\u800c\u968f\u7740 Docker \u5f97\u5230\u4e86\u666e\u53ca\uff0c\u5b83\u5f00\u59cb\u53d8\u5f97\u8d8a\u6765\u8d8a\u590d\u6742\u3002\u6700\u7ec8\uff0c\u6211\u4eec\u5728 \u200b\u200bPodman\u200b\u200b \u5f97\u5230\u4e86\u6211\u4eec\u6240\u671f\u671b\u7684\u5bb9\u5668\u7ba1\u7406\u7cfb\u7edf\uff1a\u4e00\u4e2a\u65e0\u5b88\u62a4\u8fdb\u7a0b\u7684\u5bb9\u5668\u5f15\u64ce\uff0c\u5b83\u4f7f\u5bb9\u5668\u548c\u540a\u8231\u6613\u4e8e\u6784\u5efa\u3001\u8fd0\u884c\u548c\u7ba1\u7406\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/a><\/p>\n

\u5bb9\u5668\u76f4\u63a5\u4e0e Linux \u5185\u6838\u80fd\u529b\uff08\u5982\u63a7\u5236\u7ec4\u548c\u547d\u540d\u7a7a\u95f4\uff09\u4ea4\u4e92\uff0c\u5b83\u4eec\u5728\u8fd9\u4e9b\u547d\u540d\u7a7a\u95f4\u4e2d\u4ea7\u751f\u5927\u91cf\u7684\u65b0\u8fdb\u7a0b\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u8fd0\u884c\u4e00\u4e2a\u5bb9\u5668\u5b9e\u9645\u4e0a\u5c31\u662f\u5728 Linux \u7cfb\u7edf\u5185\u90e8\u8fd0\u884c\u4e00\u4e2a Linux \u7cfb\u7edf\u3002\u4ece\u64cd\u4f5c\u7cfb\u7edf\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u5b83\u770b\u8d77\u6765\u975e\u5e38\u50cf\u4e00\u79cd\u7ba1\u7406\u548c\u7279\u6743\u6d3b\u52a8\u3002\u666e\u901a\u7528\u6237\u901a\u5e38\u4e0d\u80fd\u50cf\u5bb9\u5668\u90a3\u6837\u81ea\u7531\u652f\u914d\u7cfb\u7edf\u8d44\u6e90\uff0c\u6240\u4ee5\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8fd0\u884c Podman \u9700\u8981 root \u6216 \u200b\u200bsudo\u200b\u200b\u200b \u6743\u9650\u3002\u7136\u800c\uff0c\u8fd9\u53ea\u662f\u9ed8\u8ba4\u8bbe\u7f6e\uff0c\u800c\u4e14\u8fd9\u7edd\u4e0d\u662f\u552f\u4e00\u53ef\u7528\u7684\u8bbe\u7f6e\u3002\u672c\u6587\u6f14\u793a\u4e86\u5982\u4f55\u914d\u7f6e\u4f60\u7684 Linux \u7cfb\u7edf\uff0c\u4f7f\u666e\u901a\u7528\u6237\u53ef\u4ee5\u5728\u4e0d\u4f7f\u7528 \u200b\u200bsudo\u200b\u200b \u7684\u60c5\u51b5\u4e0b\uff08\u201c\u65e0\u6839rootless\u201d\uff09\u8fd0\u884c Podman\u3002<\/p>\n

\u547d\u540d\u7a7a\u95f4\u7684\u7528\u6237 ID<\/strong><\/span><\/div>\n

\u200b\u200b\u5185\u6838\u547d\u540d\u7a7a\u95f4\u200b\u200b \u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u865a\u6784\u7684\u7ed3\u6784\uff0c\u53ef\u5e2e\u52a9 Linux \u8ddf\u8e2a\u54ea\u4e9b\u8fdb\u7a0b\u5c5e\u4e8e\u540c\u4e00\u7c7b\u3002\u8fd9\u662f Linux \u4e2d\u7684\u201c\u961f\u5217\u62a4\u680f\u201d\u3002\u4e00\u4e2a\u961f\u5217\u4e2d\u7684\u8fdb\u7a0b\u4e0e\u53e6\u4e00\u4e2a\u961f\u5217\u4e2d\u7684\u8fdb\u7a0b\u4e4b\u95f4\u5b9e\u9645\u4e0a\u6ca1\u6709\u533a\u522b\uff0c\u4f46\u53ef\u4ee5\u5c06\u5b83\u4eec\u7528\u201c\u8b66\u6212\u7ebf\u201d\u5f7c\u6b64\u9694\u79bb\u3002\u8981\u58f0\u660e\u4e00\u7ec4\u8fdb\u7a0b\u4e3a\u201c\u5bb9\u5668\u201d\uff0c\u800c\u53e6\u4e00\u7ec4\u8fdb\u7a0b\u4e3a\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5c06\u5b83\u4eec\u5206\u5f00\u662f\u5173\u952e\u3002<\/p>\n

Linux \u901a\u8fc7\u7528\u6237 ID\uff08UID\uff09\u548c\u7ec4 ID\uff08GID\uff09\u6765\u8ddf\u8e2a\u54ea\u4e2a\u7528\u6237\u6216\u7ec4\u62e5\u6709\u7684\u8fdb\u7a0b\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u4e00\u4e2a\u7528\u6237\u53ef\u4ee5\u8bbf\u95ee\u4e00\u5343\u4e2a\u5de6\u53f3\u7684\u4ece\u5c5e UID\uff0c\u4ee5\u5206\u914d\u7ed9\u547d\u540d\u7a7a\u95f4\u7684\u5b50\u8fdb\u7a0b\u3002\u7531\u4e8e Podman \u8fd0\u884c\u7684\u662f\u5206\u914d\u7ed9\u542f\u52a8\u5bb9\u5668\u7684\u7528\u6237\u7684\u6574\u4e2a\u4ece\u5c5e\u64cd\u4f5c\u7cfb\u7edf\uff0c\u56e0\u6b64\u4f60\u9700\u8981\u7684\u4e0d\u4ec5\u4ec5\u662f\u9ed8\u8ba4\u5206\u914d\u7684\u4ece\u5c5e UID \u548c\u4ece\u5c5e GID\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u7528 \u200b\u200busermod\u200b\u200b\u200b \u547d\u4ee4\u6388\u4e88\u4e00\u4e2a\u7528\u6237\u66f4\u591a\u7684\u4ece\u5c5e UID \u548c\u4ece\u5c5e GID\u3002\u4f8b\u5982\uff0c\u8981\u6388\u4e88\u7528\u6237 \u200b\u200btux\u200b\u200b \u66f4\u591a\u7684\u4ece\u5c5e UID \u548c\u4ece\u5c5e GID\uff0c\u9009\u62e9\u4e00\u4e2a\u8fd8\u6ca1\u5206\u914d\u7528\u6237\u7684\u9002\u5f53\u7684\u9ad8 UID\uff08\u5982 200000\uff09\uff0c\u7136\u540e\u5c06\u5176\u589e\u52a0\u51e0\u5343\uff1a<\/p>\n

\r\n$ sudo usermod \\\r\n--add-subuids 200000-265536 \\\r\n--add-subgids 200000-265536 \\\r\ntux\r\n<\/pre>\n
\u547d\u540d\u7a7a\u95f4\u8bbf\u95ee<\/strong><\/span><\/div>\n

\u5bf9\u547d\u540d\u7a7a\u95f4\u6570\u91cf\u4e5f\u6709\u9650\u5236\u3002\u8fd9\u901a\u5e38\u88ab\u8bbe\u7f6e\u5f97\u5f88\u9ad8\u3002\u4f60\u53ef\u4ee5\u7528 \u200b\u200bsystctl\u200b\u200b\uff0c\u5373\u5185\u6838\u53c2\u6570\u5de5\u5177\u6765\u9a8c\u8bc1\u7528\u6237\u7684\u547d\u540d\u7a7a\u95f4\u5206\u914d\uff1a<\/p>\n

\r\n$ sysctl --all --pattern user_namespaces\r\nuser.max_user_namespaces = 28633\r\n<\/pre>\n

\u8fd9\u662f\u5f88\u5145\u8db3\u7684\u547d\u540d\u7a7a\u95f4\uff0c\u800c\u4e14\u53ef\u80fd\u662f\u4f60\u7684\u53d1\u884c\u7248\u9ed8\u8ba4\u8bbe\u7f6e\u7684\u3002\u5982\u679c\u4f60\u7684\u53d1\u884c\u7248\u6ca1\u6709\u8fd9\u4e2a\u5c5e\u6027\u6216\u8005\u8bbe\u7f6e\u5f97\u5f88\u4f4e\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u5728\u6587\u4ef6 \u200b\u200b\/etc\/sysctl.d\/userns.conf\u200b\u200b<\/span> \u4e2d\u8f93\u5165\u8fd9\u6837\u7684\u6587\u672c\u6765\u521b\u5efa\u5b83\uff1a<\/p>\n

\r\nuser.max_user_namespaces=28633\r\n<\/pre>\n

\u52a0\u8f7d\u8be5\u8bbe\u7f6e\uff1a<\/p>\n

\r\n$ sudo sysctl -p \/etc\/sysctl.d\/userns.conf\r\n<\/pre>\n
\u5728\u6ca1\u6709 root \u6743\u9650\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c\u4e00\u4e2a\u5bb9\u5668<\/strong><\/span><\/div>\n

\u5f53\u4f60\u8bbe\u7f6e\u597d\u4f60\u7684\u914d\u7f6e\uff0c\u91cd\u542f\u4f60\u7684\u8ba1\u7b97\u673a\uff0c\u4ee5\u786e\u4fdd\u4f60\u7684\u7528\u6237\u548c\u5185\u6838\u53c2\u6570\u7684\u53d8\u5316\u88ab\u52a0\u8f7d\u548c\u6fc0\u6d3b\u3002<\/p>\n

\u91cd\u542f\u540e\uff0c\u8bd5\u7740\u8fd0\u884c\u4e00\u4e2a\u5bb9\u5668\u955c\u50cf\uff1a<\/p>\n

\r\n$ podman run -it busybox echo \"hello\"\r\nhello\r\n<\/pre>\n
\u5bb9\u5668\u50cf\u547d\u4ee4\u4e00\u6837<\/strong><\/span><\/div>\n

\u5982\u679c\u4f60\u662f\u7b2c\u4e00\u6b21\u63a5\u89e6\u5bb9\u5668\uff0c\u53ef\u80fd\u4f1a\u89c9\u5f97\u5f88\u795e\u79d8\uff0c\u4f46\u5b9e\u9645\u4e0a\uff0c\u5b83\u4eec\u4e0e\u4f60\u73b0\u6709\u7684 Linux \u7cfb\u7edf\u6ca1\u6709\u4ec0\u4e48\u4e0d\u540c\u3002\u5b83\u4eec\u5b9e\u9645\u4e0a\u662f\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u6ca1\u6709\u4eff\u771f\u73af\u5883\u6216\u865a\u62df\u673a\u7684\u6210\u672c\u548c\u969c\u788d\u3002\u5bb9\u5668\u548c\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u7684\u533a\u522b\u53ea\u662f\u5185\u6838\u547d\u540d\u7a7a\u95f4\uff0c\u6240\u4ee5\u5b83\u4eec\u5b9e\u9645\u4e0a\u53ea\u662f\u5e26\u6709\u4e0d\u540c\u6807\u7b7e\u7684\u672c\u5730\u8fdb\u7a0b\u3002Podman \u4f7f\u8fd9\u4e00\u70b9\u6bd4\u4ee5\u5f80\u66f4\u52a0\u660e\u663e\uff0c\u5f53\u4f60\u5c06 Podman \u914d\u7f6e\u4e3a\u65e0\u6839\u547d\u4ee4\uff0c\u5bb9\u5668\u611f\u89c9\u66f4\u50cf\u547d\u4ee4\u800c\u4e0d\u662f\u865a\u62df\u73af\u5883\u3002Podman \u4f7f\u5bb9\u5668\u548c\u540a\u8231\u53d8\u5f97\u7b80\u5355\uff0c\u6240\u4ee5\u8bf7\u8bd5\u4e00\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5bb9\u5668\u76f4\u63a5\u4e0e Linux \u5185\u6838\u80fd\u529b\uff08\u5982\u63a7\u5236\u7ec4\u548c\u547d\u540d\u7a7a\u95f4\uff09\u4ea4\u4e92\uff0c\u5b83\u4eec\u5728\u8fd9\u4e9b\u547d\u540d\u7a7a\u95f4\u4e2d\u4ea7\u751f\u5927\u91cf\u7684\u65b0\u8fdb\u7a0b\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u8fd0 […]<\/p>\n","protected":false},"author":643,"featured_media":234489,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-234461","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\/234461","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\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=234461"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234461\/revisions"}],"predecessor-version":[{"id":234488,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234461\/revisions\/234488"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/234489"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=234461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=234461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=234461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}