{"id":306,"date":"2023-04-16T15:53:44","date_gmt":"2023-04-16T07:53:44","guid":{"rendered":"https:\/\/www.bunnyism.com\/?p=306"},"modified":"2024-12-18T21:47:06","modified_gmt":"2024-12-18T13:47:06","slug":"dockerfile-%e7%bc%96%e5%86%99","status":"publish","type":"post","link":"https:\/\/www.bunnyism.com\/?p=306","title":{"rendered":"Dockerfile \u7f16\u5199"},"content":{"rendered":"<h2 class=\"lake-content\"><span class=\"ne-text\">\u4ec0\u4e48\u662fDockerfile<\/span><\/h2>\n<div class=\"lake-content\">\n<p id=\"u2633314e\" class=\"ne-p\"><span class=\"ne-text\">\u6240\u8c13\u7684Dockefile\u662f\u6784\u5efa\u955c\u50cf\u7684\u4e00\u79cd\u65b9\u5f0f\u3002docker daemon\u5b88\u62a4\u8fdb\u7a0b\u53ef\u4ee5\u57fa\u4e8eDockefile\u7684\u6307\u4ee4\u6784\u5efa\u4e00\u4e2a\u65b0\u7684\u955c\u50cf\u3002<\/span><\/p>\n<h2 class=\"lake-content\"><span class=\"ne-text\">Dockerfile\u548c\u955c\u50cf\u7684\u533a\u522b<\/span><\/h2>\n<div class=\"lake-content\">\n<p id=\"u965edcd9\" class=\"ne-p\"><span class=\"ne-text\">\u955c\u50cf\u672c\u8eab\u662f\u4e00\u4e2a\u53ef\u4ee5\u76f4\u63a5\u542f\u52a8\u4e3a\u5bb9\u5668\u7684\u53ea\u8bfb\u76ee\u5f55\u7ed3\u6784\uff0c\u800c\u5bb9\u5668\u65f6\u4e00\u4e2a\u8bfb\u5199\u7684\u76ee\u5f55\u7ed3\u6784\uff0c\u7528\u6237\u770b\u5230\u7684\u662f\u955c\u50cf\u7684\u76ee\u5f55\u7ed3\u6784\u548c\u5bb9\u5668\u7684\u76ee\u5f55\u7ed3\u6784\u7684\u5408\u5e76merged\u5c55\u793a\u5c42\u3002<\/span><\/p>\n<p id=\"u6b473041\" class=\"ne-p\"><span class=\"ne-text\">\u800cDockefile\u672c\u8eab\u5e76\u4e0d\u662f\u955c\u50cf\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528&#8221;docker image build&#8221;\u57fa\u4e8e\u8be5\u6587\u4ef6\u8fdb\u884c\u7f16\u8bd1\u751f\u6210\u955c\u50cf\u3002<\/span><\/p>\n<h3>\u4f18\u70b9<\/h3>\n<blockquote><p>\u00a01.\u53ef\u4ee5\u5229\u7528\u7f13\u5b58\u6280\u672f;<br \/>\n2.\u4fee\u6539\u6bd4\u8f83\u65b9\u4fbf;<br \/>\n3.\u5360\u7528\u4f53\u79ef\u8f83\u5c0f;<br \/>\n4.\u4f20\u8f93\u65b9\u4fbf<\/p><\/blockquote>\n<h2>dockerfile \u5e38\u7528\u547d\u4ee4<\/h2>\n<blockquote><p>Dockefile\u7684\u5e38\u7528\u6307\u4ee4(16+)<br \/>\n&#8211; FROM<br \/>\n&#8211; MAINTAINER<br \/>\n&#8211; LABEL<br \/>\n&#8211; ADD<br \/>\n&#8211; COPY<br \/>\n&#8211; EXPOSE<br \/>\n&#8211; CMD<br \/>\n&#8211; ENTRYPOINT<br \/>\n&#8211; VOLUME<br \/>\n&#8211; HEALTHCHECK<br \/>\n&#8211; RUN<br \/>\n&#8211; ONBUILD<br \/>\n&#8211; ENV<br \/>\n&#8211; ARG<br \/>\n&#8211; USER<br \/>\n&#8211; SHELL<\/p><\/blockquote>\n<h3>dockerfile\u6587\u4ef6<\/h3>\n<blockquote><p># \u6307\u5b9a\u57fa\u7840\u955c\u50cf\uff0c\u8868\u793a\u57fa\u4e8e\u54ea\u4e2a\u955c\u50cf\u542f\u52a8\u65b0\u7684\u5bb9\u5668<br \/>\nFROM alpine<\/p>\n<p># \u58f0\u660e\u4f5c\u8005\u4fe1\u606f<br \/>\nMAINTAINER JasonYin www.oldboyedu.com linux94 y1053419035@qq.com<\/p>\n<p># \u5728\u5bb9\u5668\u4e2d\u8fd0\u884c\u547d\u4ee4<br \/>\nRUN sed -i &#8216;s#https\\?:\/\/dl-cdn.alpinelinux.org\/alpine#https:\/\/mirrors.tuna.tsinghua.edu.cn\/alpine#g&#8217; \/etc\/apk\/repositories &amp;&amp; \\<br \/>\napk add nginx &amp;&amp; \\<br \/>\nmkdir \/usr\/share\/nginx\/html &amp;&amp; \\<br \/>\necho www.oldboyedu.com &gt; \/usr\/share\/nginx\/html\/index.html &amp;&amp; \\<br \/>\nrm -rf \/var\/cache\/<\/p>\n<p># \u62f7\u8d1d\u672c\u5730\u6587\u4ef6\u5230\u5bb9\u5668\u7684\u6307\u5b9a\u8def\u5f84<br \/>\nCOPY oldboyedu-nginx.conf \/etc\/nginx\/http.d\/default.conf<\/p>\n<p># \u6307\u5b9a\u542f\u52a8\u6307\u4ee4<br \/>\nCMD [&#8220;nginx&#8221;,&#8221;-g&#8221;,&#8221;daemon off;&#8221;]<\/p><\/blockquote>\n<h2 class=\"lake-content\"><span class=\"ne-text\">\u7f16\u8bd1\u955c\u50cf<\/span><\/h2>\n<blockquote><p>docker image build -t test:v1.0 .<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h2 id=\"iA4lN\"><span class=\"ne-text\">\u542f\u52a8\u81ea\u5b9a\u4e49\u7684\u955c\u50cf<\/span><\/h2>\n<p>docker run &#8211;name web -dp 80:80 test:v1.0<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662fDockerfile \u6240\u8c13\u7684Dockefile\u662f\u6784\u5efa\u955c\u50cf\u7684\u4e00\u79cd\u65b9\u5f0f\u3002docker daemon\u5b88\u62a4\u8fdb\u7a0b\u53ef [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":194,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-306","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=306"}],"version-history":[{"count":7,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":561,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions\/561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/media\/194"}],"wp:attachment":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}