{"id":3023,"date":"2025-12-01T21:10:28","date_gmt":"2025-12-01T13:10:28","guid":{"rendered":"https:\/\/linuxjk.cn\/?p=3023"},"modified":"2025-12-01T21:10:31","modified_gmt":"2025-12-01T13:10:31","slug":"docker%e5%ba%95%e5%b1%82%e5%8e%9f%e7%90%86%e5%8f%8a%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/linuxjk.cn\/?p=3023","title":{"rendered":"docker\u5e95\u5c42\u539f\u7406\u53ca\u5e38\u89c1\u95ee\u9898"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#docker%E9%9D%A2%E8%AF%95%E9%97%AE%E9%A2%98\" >docker\u9762\u8bd5\u95ee\u9898<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#docker%E7%BD%91%E7%BB%9C%E7%B1%BB%E5%9E%8B\" >docker\u7f51\u7edc\u7c7b\u578b<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#%E8%B7%A8%E4%B8%BB%E6%9C%BA%E7%9A%84%E7%BD%91%E7%BB%9C%E7%B1%BB%E5%9E%8B%EF%BC%9A\" >\u8de8\u4e3b\u673a\u7684\u7f51\u7edc\u7c7b\u578b\uff1a<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#%E5%88%9B%E5%BB%BA%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BD%91%E7%BB%9C\" >\u521b\u5efa\u81ea\u5b9a\u4e49\u7f51\u7edc<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#%E5%88%9B%E5%BB%BA1721001024_%E6%A1%A5%E6%8E%A5%E7%9A%84\" >\u521b\u5efa172.100.1.0\/24 \u6865\u63a5\u7684<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#host%E6%A8%A1%E5%BC%8F%E7%BD%91%E7%BB%9C\" >host\u6a21\u5f0f\u7f51\u7edc<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#%E5%B0%8F%E7%BB%93\" >\u5c0f\u7ed3:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#docker%E5%BA%95%E5%B1%82%E5%8E%9F%E7%90%86%E5%BA%95%E5%B1%82%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0\" >docker\u5e95\u5c42\u539f\u7406,\u5e95\u5c42\u5982\u4f55\u5b9e\u73b0?<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#namespace\" >namespace<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#namespace%E5%88%86%E7%B1%BB%EF%BC%9A\" >namespace\u5206\u7c7b\uff1a<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#%E5%AE%B9%E5%99%A8%E4%B8%ADnamespace%E5%92%8C%E5%AE%BF%E4%B8%BB%E6%9C%BAnamespace\" >\u5bb9\u5668\u4e2dnamespace\u548c\u5bbf\u4e3b\u673anamespace:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#cgroups\" >cgroups<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#%E5%86%85%E6%A0%B8%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99\" >\u5185\u6838\u53c2\u8003\u8d44\u6599<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#%E9%9D%A2%E8%AF%95%E9%A2%98%E5%90%88%E9%9B%86\" >\u9762\u8bd5\u9898\u5408\u96c6<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#1_%E5%A6%82%E4%BD%95%E6%8F%90%E5%8F%96%E6%97%A5%E5%BF%97%E4%B8%AD%E5%85%B3%E9%94%AE%E9%94%99%E8%AF%AF\" >1. \u5982\u4f55\u63d0\u53d6\u65e5\u5fd7\u4e2d\u5173\u952e\u9519\u8bef<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#2_docker-compose%EF%BC%8Cnginx%E4%BD%BF%E7%94%A8docker%E5%90%AF%E5%8A%A8%EF%BC%8C%E6%B6%89%E5%8F%8A%E5%88%B0%E4%B8%83%E5%85%AB%E4%B8%AA%E5%9F%9F%E5%90%8D%EF%BC%8C%E4%BD%BF%E7%94%A8docker-compoesdocker_run%E8%BF%9B%E8%A1%8C%E7%AE%A1%E7%90%86%EF%BC%8C%E8%AE%BE%E8%AE%A1%E4%B8%80%E4%B8%8B%E6%8C%82%E8%BD%BD%E6%95%B0%E6%8D%AE%E7%9A%84%E9%80%BB%E8%BE%91%EF%BC%8C%E6%8A%8A%E5%85%B3%E9%94%AE%E7%9A%84%E6%96%87%E4%BB%B6%E7%9B%AE%E5%BD%95%E6%8C%82%E8%BD%BD%E5%87%BA%E6%9D%A5%EF%BC%9B%E8%A7%84%E5%88%92%E4%B8%80%E4%B8%8B%EF%BC%9B\" >2. docker-compose\uff0cnginx\u4f7f\u7528docker\u542f\u52a8\uff0c\u6d89\u53ca\u5230\u4e03\u516b\u4e2a\u57df\u540d\uff0c\u4f7f\u7528docker-compoes\/docker run\u8fdb\u884c\u7ba1\u7406\uff0c\u8bbe\u8ba1\u4e00\u4e0b\u6302\u8f7d\u6570\u636e\u7684\u903b\u8f91\uff0c\u628a\u5173\u952e\u7684\u6587\u4ef6\u76ee\u5f55\u6302\u8f7d+\u51fa\u6765\uff1b\u89c4\u5212\u4e00\u4e0b\uff1b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#3_dockerfile%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E7%9A%84%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA%EF%BC%9Fdocker%E6%80%8E%E4%B9%88%E5%B0%86%E6%9C%8D%E5%8A%A1%E6%97%A5%E5%BF%97%E6%9A%B4%E9%9C%B2%E5%87%BA%E6%9D%A5%EF%BC%9F\" >3. dockerfile\u5982\u4f55\u5b9e\u73b0\u65e5\u5fd7\u7684\u6807\u51c6\u8f93\u51fa\uff1fdocker\u600e\u4e48\u5c06\u670d\u52a1\u65e5\u5fd7\u66b4\u9732\u51fa\u6765\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#4_docker%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E5%88%87%E5%89%B2%E8%BD%AE%E8%AF%A2%EF%BC%9F\" >4. docker\u5982\u4f55\u5b9e\u73b0\u65e5\u5fd7\u5207\u5272\/\u8f6e\u8be2\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#5_%E4%BD%A0%E5%9C%A8%E4%BD%BF%E7%94%A8k8s%E4%BD%BF%E7%94%A8%E8%BF%87dockerfile%E7%9A%84%E5%A4%9A%E9%98%B6%E6%AE%B5%E6%9E%84%E5%BB%BA%E5%90%97%EF%BC%9F%E5%A5%BD%E5%A4%84%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\" >5. \u4f60\u5728\u4f7f\u7528k8s\u4f7f\u7528\u8fc7dockerfile\u7684\u591a\u9636\u6bb5\u6784\u5efa\u5417\uff1f\u597d\u5904\u662f\u4ec0\u4e48\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#6_dockerfile%E9%87%8C%E9%9D%A2%E5%9C%A8%E5%AE%B9%E5%99%A8%E4%BD%9C%E4%B8%BA%E5%AE%88%E6%8A%A4%E8%BF%9B%E7%A8%8B%E7%9A%84%E6%8C%87%E4%BB%A4%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\" >6. dockerfile\u91cc\u9762\u5728\u5bb9\u5668\u4f5c\u4e3a\u5b88\u62a4\u8fdb\u7a0b\u7684\u6307\u4ee4\u662f\u4ec0\u4e48\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#7_%E4%BD%A0%E8%AF%B4%E4%B8%80%E4%B8%8B%E5%86%99%E4%B8%80%E4%B8%AADockerfile%E7%9A%84%E5%85%A8%E9%83%A8%E6%B5%81%E7%A8%8B%EF%BC%9F%E8%AF%B4%E4%B8%8B%E4%BD%A0%E7%86%9F%E6%82%89%E7%9A%84dockerfile%E7%9A%84%E6%8C%87%E4%BB%A4%EF%BC%8C%E5%85%B6%E4%B8%ADCMD%E5%92%8CENTRYPOINT%E7%9A%84%E5%8C%BA%E5%88%AB%E6%98%AF%E5%95%A5%EF%BC%9FARG%E5%92%8CENV%E5%8C%BA%E5%88%AB%EF%BC%9FCOPY%E5%92%8CADD%E7%9A%84%E5%8C%BA%E5%88%AB%E5%91%A2%EF%BC%9F\" >7. \u4f60\u8bf4\u4e00\u4e0b\u5199\u4e00\u4e2aDockerfile\u7684\u5168\u90e8\u6d41\u7a0b\uff1f\u8bf4\u4e0b\u4f60\u719f\u6089\u7684dockerfile\u7684\u6307\u4ee4\uff0c\u5176\u4e2dCMD\u548cENTRYPOINT\u7684\u533a\u522b\u662f\u5565\uff1fARG\u548cENV\u533a\u522b\uff1fCOPY\u548cADD\u7684\u533a\u522b\u5462\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#8_dockerfile%E6%9C%89%E8%87%AA%E5%B7%B1%E5%86%99%E5%90%97_dockerfile_%E5%86%85%E5%AE%B9\" >8. dockerfile\u6709\u81ea\u5df1\u5199\u5417? dockerfile \u5185\u5bb9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#9_dockerfile_%E4%B8%AD%E4%B8%8B%E8%BD%BD%E8%B5%84%E6%BA%90%E7%9A%84%E6%96%B9%E5%BC%8F\" >9. dockerfile \u4e2d\u4e0b\u8f7d\u8d44\u6e90\u7684\u65b9\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#10_dockerfile%E7%9A%84add%E5%92%8Ccopy%E7%9A%84%E5%8C%BA%E5%88%AB\" >10. dockerfile\u7684add\u548ccopy\u7684\u533a\u522b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#11_%E4%BD%A0%E6%98%AF%E5%90%A6%E7%94%A8%E8%BF%87dockerfile%E7%9A%84cmd%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8%E7%9A%84pid\" >11. \u4f60\u662f\u5426\u7528\u8fc7dockerfile\u7684cmd\u67e5\u770b\u5bb9\u5668\u7684pid<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#12_docker%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%BC%8F\" >12. docker\u7f51\u7edc\u6a21\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#13_docker%E5%8E%9F%E7%90%86\" >13. docker\u539f\u7406<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#14_docker%E7%9A%84%E9%95%9C%E5%83%8F%E5%88%86%E5%B1%82\" >14. docker\u7684\u955c\u50cf\u5206\u5c42?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#15_k8s%E5%92%8Cdockers%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%9F\" >15. k8s\u548cdockers\u7684\u533a\u522b\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#16_docker%E5%A6%82%E4%BD%95%E4%BF%9D%E6%8C%81%E6%96%87%E4%BB%B6%E5%B1%82%E7%BA%A7\" >16. docker\u5982\u4f55\u4fdd\u6301\u6587\u4ef6\u5c42\u7ea7?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#17_docker%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6deamonjson%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%8F%82%E6%95%B0%E6%9C%89%E5%93%AA%E4%BA%9B%EF%BC%9F\" >17. docker\u914d\u7f6e\u6587\u4ef6deamon.json\u7684\u914d\u7f6e\u6587\u4ef6\u53c2\u6570\u6709\u54ea\u4e9b\uff1f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/linuxjk.cn\/?p=3023\/#18_%E5%AE%B9%E5%99%A8%E6%97%A0%E6%B3%95%E5%90%AF%E5%8A%A8%E5%A6%82%E4%BD%95%E6%8E%92%E6%9F%A5\" >18. \u5bb9\u5668\u65e0\u6cd5\u542f\u52a8\u5982\u4f55\u6392\u67e5?<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"docker%E9%9D%A2%E8%AF%95%E9%97%AE%E9%A2%98\"><\/span><strong>docker<\/strong>\u9762\u8bd5\u95ee\u9898<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"docker%E7%BD%91%E7%BB%9C%E7%B1%BB%E5%9E%8B\"><\/span>docker\u7f51\u7edc\u7c7b\u578b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201093600055.png\" alt=\"image-20251201093552972\"\/><\/figure>\n\n\n\n<p><strong>\u6865\u63a5\u6a21\u5f0f\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201093614016.png\" alt=\"image-20251201093613963\"\/><\/figure>\n\n\n\n<p><strong>host\u6a21\u5f0f\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201093638443.png\" alt=\"image-20251201093638399\"\/><\/figure>\n\n\n\n<p><strong>Container\u6a21\u5f0f\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201093703227.png\" alt=\"image-20251201093703190\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%B7%A8%E4%B8%BB%E6%9C%BA%E7%9A%84%E7%BD%91%E7%BB%9C%E7%B1%BB%E5%9E%8B%EF%BC%9A\"><\/span>\u8de8\u4e3b\u673a\u7684\u7f51\u7edc\u7c7b\u578b\uff1a<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201093825562.png\" alt=\"image-20251201093825526\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201111003688.png\" alt=\"image-20251201111003642\"\/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%88%9B%E5%BB%BA%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BD%91%E7%BB%9C\"><\/span>\u521b\u5efa\u81ea\u5b9a\u4e49\u7f51\u7edc<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">docker network &nbsp; create --help<br>Usage: docker network create [OPTIONS] NETWORK<br>Create a network<br>Options:<br> -d, --driver string &nbsp; &nbsp; &nbsp; \u6307\u5b9a\u7f51\u7edc\u7c7b\u578b,\u9ed8\u8ba4\u662f\u6865\u63a5bridge<br> &nbsp; &nbsp; &nbsp;--subnet strings &nbsp; &nbsp; &nbsp; \u6307\u5b9a\u81ea\u5b9a\u4e49\u7684\u7f51\u7edc\u7684\u7f51\u6bb5CIDR 172.100.0.0\/16<br> &nbsp; &nbsp; &nbsp;--ip-range strings &nbsp; &nbsp; \u6307\u5b9a\u81ea\u5b9a\u4e49\u7f51\u7edc\u4e2dip\u8303\u56f4CIDR 172.100.1.0\/24 &nbsp;<br> &nbsp; &nbsp; &nbsp;--gateway strings &nbsp; &nbsp; \u6307\u5b9a\u7f51\u5173<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%88%9B%E5%BB%BA1721001024_%E6%A1%A5%E6%8E%A5%E7%9A%84\"><\/span><strong>\u521b\u5efa172.100.1.0\/24 \u6865\u63a5\u7684<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">docker network create oldboy_net &nbsp;--driver bridge \\<br>--subnet 172.100.0.0\/16 \\<br>--ip-range 172.100.1.0\/24 \\<br>--gateway 172.100.0.1<br>\u200b<br>ip a | grep 172.100.0.1<br>docker run -d &nbsp;--network oldboy_net &nbsp;--name diy_net nginx:1.24<br>docker exec &nbsp; -it &nbsp; diy_net &nbsp; curl &nbsp;-I &nbsp; baidu.com<\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"host%E6%A8%A1%E5%BC%8F%E7%BD%91%E7%BB%9C\"><\/span><strong>host\u6a21\u5f0f\u7f51\u7edc<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<pre class=\"wp-block-preformatted\">docker run -d &nbsp; --network &nbsp; host &nbsp; nginx:1.24-alpine<br>docker run -d &nbsp; --network &nbsp; host &nbsp; nginx:1.24-alpine<br>docker run -d &nbsp; --network &nbsp; host &nbsp; nginx:1.24-alpine<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%B0%8F%E7%BB%93\"><\/span>\u5c0f\u7ed3:<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u5355\u673a\u7f51\u7edc\u7c7b\uff1a\u6865\u63a5,host,container\u6a21\u5f0f,none. \u8de8\u4e3b\u673a:overylay,fannel<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"docker%E5%BA%95%E5%B1%82%E5%8E%9F%E7%90%86%E5%BA%95%E5%B1%82%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0\"><\/span>docker\u5e95\u5c42\u539f\u7406,\u5e95\u5c42\u5982\u4f55\u5b9e\u73b0?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>\u5bb9\u5668\u662f \u9694\u79bb \u7684\u73af\u5883\u4e2d\u8fd0\u884c\u7684\u4e00\u4e2a \u8fdb\u7a0b ,\u5982\u679c\u8fdb\u7a0b\u7ed3\u675f,\u5bb9\u5668\u5c31\u4f1a\u505c\u6b62.<\/strong> <strong>\u7ec6\u81f4\uff1a\u5bb9\u5668\u7684\u9694\u79bb\u73af\u5883,\u62e5\u6709\u81ea\u5df1\u7684ip\u5730\u5740,\u7cfb\u7edf\u6587\u4ef6,\u4e3b\u673a\u540d,\u8fdb\u7a0b\u7ba1\u7406,\u76f8\u5f53\u4e8e\u4e00\u4e2a mini\u7684\u7cfb\u7edf .<\/strong> <strong>\u5bb9\u5668\u6280\u672f\u662f\u57fa\u4e8e Linux\u5185\u6838 \u6280\u672f\u5b9e\u73b0\u7684.<\/strong> <strong>namespace \u547d\u540d\u7a7a\u95f4,\u8d44\u6e90\u9694\u79bb.<\/strong> <strong>cgroup \u8d44\u6e90\u63a7\u5236\/\u9650\u5236.<\/strong> <strong>overlayfs \u6587\u4ef6\u7cfb\u7edf.<\/strong> <strong>chroot \u5207\u6362\u6839\u76ee\u5f55.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201111545355.png\" alt=\"image-20251201111545308\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"namespace\"><\/span><strong>namespace<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p><strong>\u521b\u5efa\u9694\u79bb\u7684\u73af\u5883<\/strong><\/p>\n\n\n\n<p><strong>\u67e5\u770b \/proc\/pid\/ns\/<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201111712961.png\" alt=\"image-20251201111712919\"\/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"namespace%E5%88%86%E7%B1%BB%EF%BC%9A\"><\/span>namespace\u5206\u7c7b\uff1a<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201111739403.png\" alt=\"image-20251201111739365\"\/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%AE%B9%E5%99%A8%E4%B8%ADnamespace%E5%92%8C%E5%AE%BF%E4%B8%BB%E6%9C%BAnamespace\"><\/span>\u5bb9\u5668\u4e2dnamespace\u548c\u5bbf\u4e3b\u673anamespace:<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201111800947.png\" alt=\"image-20251201111800874\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"cgroups\"><\/span><strong>cgroups<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/sys\/fs\/cgroup\/cpu<br>mkdir oldboy-cgroup<br>cd oldboy-cgroup<br>#\u538b\u529b\u6d4b\u8bd5<br>stress &nbsp;-c 4 &nbsp;-v -t 20m &nbsp;<br>#\u8fdb\u884c\u9650\u5236<br>echo 10000 &gt;cpu.cfs_quota_us<br>#\u6dfb\u52a0pid\u5230tasks\u4e2d \u5173\u8054\u4efb\u52a1<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%86%85%E6%A0%B8%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99\"><\/span><strong>\u5185\u6838\u53c2\u8003\u8d44\u6599<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p><a href=\"https:\/\/www.linux.com\/news\/understanding-and-securing-linux-namespaces\/\">Understanding and Securing Linux Namespaces &#8211; Linux.com<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/medium.com\/@saschagrunert\/demystifying-containers-part-i-kernel-space-2c53d6979504\">Demystifying Containers &#8211; Part I: Kernel Space | by Sascha Grunert | Medium<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%9D%A2%E8%AF%95%E9%A2%98%E5%90%88%E9%9B%86\"><\/span>\u9762\u8bd5\u9898\u5408\u96c6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8bf4\u660e: \u9762\u8bd5\u9898\u6c47\u603b\u4e0e\u603b\u7ed3<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_%E5%A6%82%E4%BD%95%E6%8F%90%E5%8F%96%E6%97%A5%E5%BF%97%E4%B8%AD%E5%85%B3%E9%94%AE%E9%94%99%E8%AF%AF\"><\/span>1. \u5982\u4f55\u63d0\u53d6\u65e5\u5fd7\u4e2d\u5173\u952e\u9519\u8bef<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">1) <br>\u5173\u952e\u8bcd\u8fc7\u6ee4: error\/failed\/failure\/exception\/timeout\/permission denied\/<br>2) <br>docker logs + \u8fc7\u6ee4 <br>3) docker logs &nbsp;-f \u6216--tail \u6216--since  \u6216--until &nbsp; &nbsp;-n\u6700\u540exxx\u884c\u65e5\u5fd7<br>docker logs -f &nbsp; -n 500 <br>docker logs -f &nbsp; --since  50m<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_docker-compose%EF%BC%8Cnginx%E4%BD%BF%E7%94%A8docker%E5%90%AF%E5%8A%A8%EF%BC%8C%E6%B6%89%E5%8F%8A%E5%88%B0%E4%B8%83%E5%85%AB%E4%B8%AA%E5%9F%9F%E5%90%8D%EF%BC%8C%E4%BD%BF%E7%94%A8docker-compoesdocker_run%E8%BF%9B%E8%A1%8C%E7%AE%A1%E7%90%86%EF%BC%8C%E8%AE%BE%E8%AE%A1%E4%B8%80%E4%B8%8B%E6%8C%82%E8%BD%BD%E6%95%B0%E6%8D%AE%E7%9A%84%E9%80%BB%E8%BE%91%EF%BC%8C%E6%8A%8A%E5%85%B3%E9%94%AE%E7%9A%84%E6%96%87%E4%BB%B6%E7%9B%AE%E5%BD%95%E6%8C%82%E8%BD%BD%E5%87%BA%E6%9D%A5%EF%BC%9B%E8%A7%84%E5%88%92%E4%B8%80%E4%B8%8B%EF%BC%9B\"><\/span>2. docker-compose\uff0cnginx\u4f7f\u7528docker\u542f\u52a8\uff0c\u6d89\u53ca\u5230\u4e03\u516b\u4e2a\u57df\u540d\uff0c\u4f7f\u7528docker-compoes\/docker run\u8fdb\u884c\u7ba1\u7406\uff0c\u8bbe\u8ba1\u4e00\u4e0b\u6302\u8f7d\u6570\u636e\u7684\u903b\u8f91\uff0c\u628a\u5173\u952e\u7684\u6587\u4ef6\u76ee\u5f55\u6302\u8f7d+\u51fa\u6765\uff1b\u89c4\u5212\u4e00\u4e0b\uff1b<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">1. \u624b\u52a8\u8fd0\u884c\u4e0e\u914d\u7f6e<br>2. dockerfile<br>3. docker run<br>4. docker-compose\u7ba1\u7406 &nbsp; services: &nbsp;  networks:<br>\u200b<br>\u200b<br>1) docker run \u4f7f\u7528\u4e86\u4ec0\u4e48\u9009\u9879<br>a.\u5b50\u914d\u7f6e\u6587\u4ef6<br>b.\u4ee3\u7801\u76ee\u5f55<br>docker run &nbsp;-d --name &nbsp; ngx_mutil_site -p 80:80 -v &nbsp;`pwd`\/conf.d\/:\/etc\/nginx\/conf.d\/  \\<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-v &nbsp;`pwd`\/code\/:\/app\/code\/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \\<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  nginx:1.24<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> #\u6302\u8f7d\u914d\u7f6e\u6587\u4ef6(conf.d)\u5bb9\u5668\u4e2d<br> #\u6240\u6709\u9879\u76ee\u7684\u4ee3\u7801<br>2) docker-compose <br>version: '3.3'<br>serivces:<br> &nbsp; ngx_mutil_site:<br> &nbsp; &nbsp; image: nginx:1.24<br> &nbsp; &nbsp; ports:<br> &nbsp; &nbsp; &nbsp; - 80:80<br> &nbsp; &nbsp; &nbsp; - 443:443<br> &nbsp; &nbsp; volumes:<br> &nbsp; &nbsp; &nbsp; - .\/conf.d\/:\/etc\/nginx\/conf.d\/<br> &nbsp; &nbsp; &nbsp; - .\/code\/:\/app\/code\/ &nbsp;<br> &nbsp; &nbsp; &nbsp; <\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_dockerfile%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E7%9A%84%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA%EF%BC%9Fdocker%E6%80%8E%E4%B9%88%E5%B0%86%E6%9C%8D%E5%8A%A1%E6%97%A5%E5%BF%97%E6%9A%B4%E9%9C%B2%E5%87%BA%E6%9D%A5%EF%BC%9F\"><\/span>3. dockerfile\u5982\u4f55\u5b9e\u73b0\u65e5\u5fd7\u7684\u6807\u51c6\u8f93\u51fa\uff1fdocker\u600e\u4e48\u5c06\u670d\u52a1\u65e5\u5fd7\u66b4\u9732\u51fa\u6765\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">docker logs\u672c\u8d28  \u5bb9\u5668\u4e2d\u65e5\u5fd7\u6587\u4ef6\u4e0d\u8981\u5b58\u653e\u5728\u6587\u4ef6\u4e2d. \u8f93\u5165\u5230\u65e5\u5fd7\u6587\u4ef6\u7684\u5185\u5bb9,\u8f93\u51fa\u5c4f\u5e55. docker logs\u6355\u83b7.<br>\u200b<br>\u65b9\u684801: \u8f6f\u8fde\u63a5 <br>1) \u65e5\u5fd7\u6587\u4ef6\u8f6f\u8fde\u63a5\u5230\/dev\/stdout \u6216 \/dev\/stderr <br>\/dev\/stdout --&gt; \/proc\/self\/fd\/1<br>\/dev\/stderr --&gt; \/proc\/self\/fd\/2<br>\u200b<br>\/proc\/self\/fd\/1  \/proc\/self\/fd\/2 \u6307\u5411--&gt; \/dev\/pts\/0<br>\u65b9\u684802: \u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a<br>2) \u670d\u52a1\u6307\u5b9a\u65e5\u5fd7\u7684\u65f6\u5019\u76f4\u63a5\u6307\u5b9a\u5230stdout\u6216stderr <br>error_log \/dev\/stderr;<br>access_log \/dev\/stdout; <br>\u200b<br>2) docker logs\u67e5\u770b<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_docker%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E5%88%87%E5%89%B2%E8%BD%AE%E8%AF%A2%EF%BC%9F\"><\/span>4. docker\u5982\u4f55\u5b9e\u73b0\u65e5\u5fd7\u5207\u5272\/\u8f6e\u8be2\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">0. \u4e00\u822c\u7684\u670d\u52a1\u6ca1\u6709\u5bb9\u5668\u7684\u65f6\u5019,\u901a\u8fc7logrotate\u5b9e\u73b0\u65e5\u5fd7\u5207\u5272\/\u8f6e\u8be2<br>\u200b<br>1.\u5b58\u653e\u5728\u5bb9\u5668\u4fe1\u606fLogPath\u6307\u5b9a\u7684\u4f4d\u7f6e. json\u683c\u5f0f.<br>\u200b<br>\u200b<br>2.daemon.json\u6587\u4ef6 docker\u670d\u52a1\u914d\u7f6e<br>\u200b<br>{<br> &nbsp;\"registry-mirrors\": [\"https:\/\/bjjtv7cs.mirror.aliyuncs.com\"],<br> &nbsp;\"insecure-registries\": [\"reg.oldboylinux.cn:5000\",\"harbor.oldboylinux.cn\"],<br> &nbsp;\"log-driver\": \"local\",<br> &nbsp;\"log-opts\": {<br> &nbsp; &nbsp;\"max-size\": \"1g\",<br> &nbsp; &nbsp;\"max-file\": \"15\"<br> &nbsp;  }<br>}<br> &nbsp; &nbsp;\"max-size\": \"1g\", \u65e5\u5fd7\u6700\u5927\u5927\u5c0f<br> &nbsp; &nbsp;\"max-file\": \"15\"  \u65e5\u5fd7\u6570\u91cf<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_%E4%BD%A0%E5%9C%A8%E4%BD%BF%E7%94%A8k8s%E4%BD%BF%E7%94%A8%E8%BF%87dockerfile%E7%9A%84%E5%A4%9A%E9%98%B6%E6%AE%B5%E6%9E%84%E5%BB%BA%E5%90%97%EF%BC%9F%E5%A5%BD%E5%A4%84%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\"><\/span>5. \u4f60\u5728\u4f7f\u7528k8s\u4f7f\u7528\u8fc7dockerfile\u7684\u591a\u9636\u6bb5\u6784\u5efa\u5417\uff1f\u597d\u5904\u662f\u4ec0\u4e48\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\u901a\u8fc7FROM \u6307\u5b9a\u955c\u50cf\u7684\u65f6\u5019\u52a0\u4e0aAS tmp \u521b\u5efa\u4e34\u65f6\u955c\u50cf \u5176\u4ed6FROM\u4e2d\u901a\u8fc7copy  --from=tmp\u4ece\u4e34\u65f6\u955c\u50cf\u590d\u5236\u5185\u5bb9. \u597d\u5904:  \u73af\u5883\u9694\u79bb \u7f16\u8bd1\u73af\u5883 \u8fd0\u884c\u73af\u5883 \u63a7\u5236\u955c\u50cf\u5927\u5c0f \u90fd\u653e\u5728\u4e00\u8d77\u955c\u50cf\u5f88\u5927 \u66f4\u52a0\u5b89\u5168 \u7cbe\u7b80\u955c\u50cf\u5927\u5c0f. \u5e94\u7528\u573a\u666f: 1. \u7f16\u8bd1 tengine 2. java\/maven\u6253\u5305\u7f16\u8bd1  \u524d\u7aef \u6253\u5305 \u7f16\u8bd1<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_dockerfile%E9%87%8C%E9%9D%A2%E5%9C%A8%E5%AE%B9%E5%99%A8%E4%BD%9C%E4%B8%BA%E5%AE%88%E6%8A%A4%E8%BF%9B%E7%A8%8B%E7%9A%84%E6%8C%87%E4%BB%A4%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\"><\/span>6. dockerfile\u91cc\u9762\u5728\u5bb9\u5668\u4f5c\u4e3a\u5b88\u62a4\u8fdb\u7a0b\u7684\u6307\u4ee4\u662f\u4ec0\u4e48\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5b88\u62a4\u8fdb\u7a0b,\u963b\u585e.<br>\u200b<br>CMD\u6216ENTRYPOINT.<br>\u4e3e\u4f8b: nginx -g 'daemon off;' <br> &nbsp; &nbsp;  mysqld <br> &nbsp; &nbsp;  php-fpm <br> &nbsp; &nbsp;  \u811a\u672c\/entry.sh java -jar<br> &nbsp; &nbsp;  catalina.sh run<br> &nbsp; &nbsp;  tail -f xxx.log <\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_%E4%BD%A0%E8%AF%B4%E4%B8%80%E4%B8%8B%E5%86%99%E4%B8%80%E4%B8%AADockerfile%E7%9A%84%E5%85%A8%E9%83%A8%E6%B5%81%E7%A8%8B%EF%BC%9F%E8%AF%B4%E4%B8%8B%E4%BD%A0%E7%86%9F%E6%82%89%E7%9A%84dockerfile%E7%9A%84%E6%8C%87%E4%BB%A4%EF%BC%8C%E5%85%B6%E4%B8%ADCMD%E5%92%8CENTRYPOINT%E7%9A%84%E5%8C%BA%E5%88%AB%E6%98%AF%E5%95%A5%EF%BC%9FARG%E5%92%8CENV%E5%8C%BA%E5%88%AB%EF%BC%9FCOPY%E5%92%8CADD%E7%9A%84%E5%8C%BA%E5%88%AB%E5%91%A2%EF%BC%9F\"><\/span>7. \u4f60\u8bf4\u4e00\u4e0b\u5199\u4e00\u4e2aDockerfile\u7684\u5168\u90e8\u6d41\u7a0b\uff1f\u8bf4\u4e0b\u4f60\u719f\u6089\u7684dockerfile\u7684\u6307\u4ee4\uff0c\u5176\u4e2dCMD\u548cENTRYPOINT\u7684\u533a\u522b\u662f\u5565\uff1fARG\u548cENV\u533a\u522b\uff1fCOPY\u548cADD\u7684\u533a\u522b\u5462\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">1) \u6d41\u7a0b\u624b\u52a8\u6d4b\u8bd5  docker run \u624b\u52a8\u90e8\u7f72,docker cp,\u51c6\u5907\u914d\u7f6e.<br>  \u8bb0\u5f55\u6d41\u7a0b\u4e0e\u547d\u4ee4,\u64cd\u4f5c.<br> &nbsp;<br>2) \u6839\u636e\u6d41\u7a0b\u4e66\u5199dockerfile <br>  FROM <br>  LABEL <br>  ENV <br>  ADD\/COPY<br>  RUN<br>  RUN<br>  RUN<br>  EXPOSE &nbsp;<br>  VOLUME <br>  WORKDIR <br>  CMD<br>  HEALTHCHECK  \u5bb9\u5668\u5065\u5eb7\u68c0\u67e5.\u6307\u4ee4<br>  HEALTHCHECK --interval=5m --timeout=3s \\<br>  CMD curl -f http:\/\/localhost\/ || exit 1<br>  \u6307\u4ee4\u7684\u8fd4\u56de\u503c\u662f 0: success - the container is healthy and ready for use<br>  \u6307\u4ee4\u7684\u8fd4\u56de\u503c\u662f 1: unhealthy - the container is not working correctly<br>\u200b<br>3) \u6d4b\u8bd5,\u7cbe\u7b80<br>4) \u4fdd\u5b58,\u4e0a\u4f20\u5230\u955c\u50cf\u4ed3\u5e93,dk\u4fdd\u7559.<br>5) \u6e05\u7406\u672c\u5730\u955c\u50cf<br>1.tar &nbsp; ADD<br>2.\u591a\u9636\u6bb5\u6784\u5efa COPY --from<br>3. ADD\u6307\u5b9a\u7f51\u7edc\u94fe\u63a5(wget) <br>ENV \u521b\u5efa\u73af\u5883\u53d8\u91cf,dockerfile\u4e2d\u4f7f\u7528,\u811a\u672c,\u5bb9\u5668\u4f7f\u7528. \u5168\u5c40\u53d8\u91cf.<br>ARG docker build \u65f6\u5019\u901a\u8fc7--build-arg\u6307\u5b9a. dockerfile\u4e2d\u751f\u6548.<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_dockerfile%E6%9C%89%E8%87%AA%E5%B7%B1%E5%86%99%E5%90%97_dockerfile_%E5%86%85%E5%AE%B9\"><\/span>8. dockerfile\u6709\u81ea\u5df1\u5199\u5417? dockerfile \u5185\u5bb9<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u540c\u4e0a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"9_dockerfile_%E4%B8%AD%E4%B8%8B%E8%BD%BD%E8%B5%84%E6%BA%90%E7%9A%84%E6%96%B9%E5%BC%8F\"><\/span>9. dockerfile \u4e2d\u4e0b\u8f7d\u8d44\u6e90\u7684\u65b9\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5916\u90e8\u8d44\u6e90--&gt;\u955c\u50cf<br>\u200b<br>1) ADD &nbsp; nginx.org\/nginx.tar.gz &nbsp; \/tmp\/<br>2) RUN &nbsp; wget\/curl<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"10_dockerfile%E7%9A%84add%E5%92%8Ccopy%E7%9A%84%E5%8C%BA%E5%88%AB\"><\/span>10. dockerfile\u7684add\u548ccopy\u7684\u533a\u522b<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u7565<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"11_%E4%BD%A0%E6%98%AF%E5%90%A6%E7%94%A8%E8%BF%87dockerfile%E7%9A%84cmd%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8%E7%9A%84pid\"><\/span>11. \u4f60\u662f\u5426\u7528\u8fc7dockerfile\u7684cmd\u67e5\u770b\u5bb9\u5668\u7684pid<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">docker inspect <br>docker inspect &nbsp;  tomcat_zrlog  | jq  .[].State.Pid<br>\u200b<br>docker top \u5bb9\u5668\u540d\u5b57<br>docker top  01ngx_ngx_1 &nbsp;  aux \/-ef\/-efL <\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"12_docker%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%BC%8F\"><\/span>12. docker\u7f51\u7edc\u6a21\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">bridge\u6865\u63a5<br>host &nbsp;<br>container <br>none <br>\u200b<br>flannel<br>celico<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"13_docker%E5%8E%9F%E7%90%86\"><\/span>13. docker\u539f\u7406<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">ns(namespace)  \u9694\u79bb<br>cgroup &nbsp; &nbsp; &nbsp; &nbsp; \u9650\u5236<br>overlayfs &nbsp; &nbsp;  \u6587\u4ef6\u7cfb\u7edf<br>chroot &nbsp; &nbsp; &nbsp; &nbsp; \u6839<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"14_docker%E7%9A%84%E9%95%9C%E5%83%8F%E5%88%86%E5%B1%82\"><\/span>14. docker\u7684\u955c\u50cf\u5206\u5c42?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201210727334.png\" alt=\"img\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">dockerfile <br>\u57fa\u7840\u7cfb\u7edf\u955c\u50cf\u4e00\u822c\u662f\u53ea\u8bfb\u7684.<br>\u901a\u8fc7dockerfile\u4e2d\u7684\u6307\u4ee4\u7ed9\u955c\u50cf\u589e\u52a0\u65b0\u7684\u5c42\u6b21(\u4fee\u6539)<br>\u6bcf\u4e2a\u6307\u4ee4\u76f8\u5f53\u4e8e\u7ed9\u955c\u50cf\u589e\u52a0\u4e861\u5c42.(RUN,ADD,COPY)<br>\u6700\u7ec8\u751f\u6210\u6211\u4eec\u60f3\u8981\u7684\u81ea\u5b9a\u4e49\u955c\u50cf.<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/typora-zp.oss-cn-shanghai.aliyuncs.com\/typora20251201210727759.png\" alt=\"img\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"15_k8s%E5%92%8Cdockers%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%9F\"><\/span>15. k8s\u548cdockers\u7684\u533a\u522b\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"16_docker%E5%A6%82%E4%BD%95%E4%BF%9D%E6%8C%81%E6%96%87%E4%BB%B6%E5%B1%82%E7%BA%A7\"><\/span>16. docker\u5982\u4f55\u4fdd\u6301\u6587\u4ef6\u5c42\u7ea7?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\u955c\u50cf\u5206\u5c42<br>overlayfs <br>chroot<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"17_docker%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6deamonjson%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%8F%82%E6%95%B0%E6%9C%89%E5%93%AA%E4%BA%9B%EF%BC%9F\"><\/span>17. docker\u914d\u7f6e\u6587\u4ef6deamon.json\u7684\u914d\u7f6e\u6587\u4ef6\u53c2\u6570\u6709\u54ea\u4e9b\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br> &nbsp;\"registry-mirrors\": [\"https:\/\/bjjtv7cs.mirror.aliyuncs.com\"],<br> &nbsp;\"insecure-registries\": [\"reg.oldboylinux.cn:5000\",\"harbor.oldboylinux.cn\"],<br> &nbsp;\"log-driver\": \"local\",<br> &nbsp;\"log-opts\": {<br> &nbsp; &nbsp;\"max-size\": \"1g\",<br> &nbsp; &nbsp;\"max-file\": \"15\"<br> &nbsp;  }<br>}<br>{<br> &nbsp;\"registry-mirrors\": [\"https:\/\/x86ltfij.mirror.aliyuncs.com\"],<br> &nbsp;\"insecure-registries\": [\"reg.oldboylinux.cn:5000\",\"harbor.oldboylinux.cn\"],<br> &nbsp;\"features\": {<br>     &nbsp; &nbsp; &nbsp;\"buildkit\": true<br> &nbsp; }<br>}<br>\u200b<br>\u200b<br>\u200b<br>registry-mirrors \u6307\u5b9a\u955c\u50cf\u4ed3\u5e93,\u7528\u4e8e\u52a0\u901f\u7684\u5730\u5740.<br>insecure-registries \u6307\u5b9a\u672a\u52a0\u5bc6\u7684\u79c1\u6709\u955c\u50cf\u4ed3\u5e93(\u6ca1\u6709\u4f7f\u7528https)<br>log-opts \u6307\u5b9a\u65e5\u5fd7\u7684\u9009\u9879.<br>....<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"18_%E5%AE%B9%E5%99%A8%E6%97%A0%E6%B3%95%E5%90%AF%E5%8A%A8%E5%A6%82%E4%BD%95%E6%8E%92%E6%9F%A5\"><\/span>18. \u5bb9\u5668\u65e0\u6cd5\u542f\u52a8\u5982\u4f55\u6392\u67e5?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bb9\u5668\u65e0\u6cd5\u542f\u52a8<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>logs<\/li>\n\n\n\n<li>docker run -itd xxx \/bin\/bash,\u7136\u540e\u8fdb\u5165\u5bb9\u5668 \u624b\u52a8\u542f\u52a8\u670d\u52a1(CMD) \u68c0\u67e5\u8bed\u6cd5<\/li>\n\n\n\n<li>\u53ef\u4ee5\u542f\u52a8exec \u8fde\u63a5\u67e5\u770b<\/li>\n\n\n\n<li>\u591a\u5bb9\u5668,ping,telnet,tcpdump<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>docker\u9762\u8bd5\u95ee\u9898 docker\u7f51\u7edc\u7c7b\u578b \u6865\u63a5\u6a21\u5f0f\uff1a host\u6a21\u5f0f\uff1a Container\u6a21\u5f0f\uff1a \u8de8\u4e3b\u673a\u7684\u7f51\u7edc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3023","post","type-post","status-publish","format-standard","hentry","category-vxhs888p"],"_links":{"self":[{"href":"https:\/\/linuxjk.cn\/index.php?rest_route=\/wp\/v2\/posts\/3023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxjk.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxjk.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxjk.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxjk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3023"}],"version-history":[{"count":1,"href":"https:\/\/linuxjk.cn\/index.php?rest_route=\/wp\/v2\/posts\/3023\/revisions"}],"predecessor-version":[{"id":3024,"href":"https:\/\/linuxjk.cn\/index.php?rest_route=\/wp\/v2\/posts\/3023\/revisions\/3024"}],"wp:attachment":[{"href":"https:\/\/linuxjk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxjk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxjk.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}