{"id":95,"date":"2017-03-29T22:42:43","date_gmt":"2017-03-29T14:42:43","guid":{"rendered":"http:\/\/www.jsjs.org\/?p=95"},"modified":"2017-03-29T22:42:43","modified_gmt":"2017-03-29T14:42:43","slug":"dockerfile%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=95","title":{"rendered":"Dockerfile\u8be6\u89e3"},"content":{"rendered":"<p><a class=\"tag_link\" title=\"\u67e5\u770bDocker\u4e2d\u7684\u5168\u90e8\u6587\u7ae0\" href=\"http:\/\/www.showerlee.com\/archives\/tag\/docker\">Docker<\/a>\u53ef\u4ee5\u901a\u8fc7\u83b7\u53d6<a class=\"tag_link\" title=\"\u67e5\u770bDocker\u4e2d\u7684\u5168\u90e8\u6587\u7ae0\" href=\"http:\/\/www.showerlee.com\/archives\/tag\/docker\">Docker<\/a>file\u7f16\u5199\u7684\u547d\u4ee4\u81ea\u52a8Build\u51fa\u4e00\u4e2a\u65b0\u7684\u955c\u50cf,\u91cc\u9762\u7684<a class=\"tag_link\" title=\"\u67e5\u770bDocker\u4e2d\u7684\u5168\u90e8\u6587\u7ae0\" href=\"http:\/\/www.showerlee.com\/archives\/tag\/docker\">Docker<\/a>\u5185\u5efa\u547d\u4ee4\u4f1a\u5e2e\u52a9\u6211\u4eec\u5728\u5df2\u6709\u7684image\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9a\u5236image.<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u5148\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e9b\u5e38\u7528<a class=\"tag_link\" title=\"\u67e5\u770bDocker\u4e2d\u7684\u5168\u90e8\u6587\u7ae0\" href=\"http:\/\/www.showerlee.com\/archives\/tag\/docker\">Docker<\/a>file\u7f16\u5199\u89c4\u8303.<\/p>\n<p><a class=\"tag_link\" title=\"\u67e5\u770bDocker\u4e2d\u7684\u5168\u90e8\u6587\u7ae0\" href=\"http:\/\/www.showerlee.com\/archives\/tag\/docker\">Docker<\/a>\u914d\u7f6e\u4f20\u9001\u95e8:\u00a0<a href=\"http:\/\/www.showerlee.com\/archives\/1758\" rel=\"nofollow\">http:\/\/www.showerlee.com\/archives\/1758<\/a><\/p>\n<p>1.FROM<\/p>\n<p>FROM &lt;image&gt;:&lt;tag&gt;<\/p>\n<p>FROM\u4f1a\u4f7f\u7528\u5f53\u524d\u672c\u5730\u6216\u8005\u8fdc\u7a0b<a class=\"tag_link\" title=\"\u67e5\u770bDocker\u4e2d\u7684\u5168\u90e8\u6587\u7ae0\" href=\"http:\/\/www.showerlee.com\/archives\/tag\/docker\">Docker<\/a>\u4ed3\u5e93\u7684image, \u8fd9\u4e2a\u8981\u9996\u5148\u5199\u5230\u8be5\u811a\u672c\u7684\u7b2c\u4e00\u884c.<\/p>\n<p>\u4f8b:<\/p>\n<pre class=\"prettyprint lang-bsh\">FROM centos67base\/apache:apache_base<\/pre>\n<p>\u8fd9\u91cc\u4ee3\u8868\u6211\u4eec\u4f7f\u7528\u672c\u5730\u7684centos67base\/apache\u955c\u50cf.<\/p>\n<p>\u67e5\u770b\u672c\u5730\u7f13\u5b58\u955c\u50cf\u53ef\u4ee5\u4f7f\u7528<\/p>\n<p># docker images<\/p>\n<p>2.MAINTAINER<\/p>\n<p>MAINTAINER &lt;name&gt;<\/p>\n<p>\u8fd9\u4e2a\u4f1a\u7ed9\u751f\u6210\u7684\u955c\u50cf\u521b\u5efa\u4e00\u4e2a\u4f5c\u8005\u540d<\/p>\n<p>3.RUN<\/p>\n<p>RUN &lt;command&gt; (\u547d\u4ee4\u884c\u683c\u5f0f, \u6267\u884c\u4e00\u6bb5shell\u547d\u4ee4)<\/p>\n<p>RUN [&#8220;executable&#8221;, &#8220;param1&#8221;, &#8220;param2&#8221;] (\u5217\u8868\u683c\u5f0f, &#8220;executable&#8221;\u53ef\u4ee5\u66f4\u6539\u4e0d\u540cshell\u683c\u5f0f, \u4f8b\u5982\/bin\/sh\u6216\/bin\/bash, &#8220;param1&#8243;\u4ee3\u8868shell\u53c2\u6570)<\/p>\n<p>\u8fd9\u4e2a\u53ef\u4ee5\u7406\u89e3\u4e3a\u6267\u884cshell\u547d\u4ee4\u5230image, \u4e00\u822c\u6765\u8bf4\u7528\u6765\u7ed9\u955c\u50cf\u5b89\u88c5package, \u6216\u8005\u66f4\u6539\u7cfb\u7edf\u914d\u7f6e\u7b49.<\/p>\n<p>\u4f8b:<\/p>\n<pre class=\"prettyprint lang-bsh\">RUN \/bin\/bash -c echo 123\nRUN [\"\/bin\/bash\" \"-c\" \"echo 123\"]<\/pre>\n<p>4.CMD<\/p>\n<p>CMD [&#8220;executable&#8221;,&#8221;param1&#8243;,&#8221;param2&#8243;] (\u540cRUN)<\/p>\n<p>CMD [&#8220;param1&#8243;,&#8221;param2&#8221;] (\u4f7f\u7528\u7cfb\u7edf\u9ed8\u8ba4shell)<\/p>\n<p>CMD command param1 param2 (\u547d\u4ee4\u884c\u683c\u5f0f)<\/p>\n<p>\u8fd9\u4e2aCMD\u57fa\u672c\u4f7f\u7528\u683c\u5f0f\u4e0eRUN\u7c7b\u4f3c, \u533a\u522b\u5728\u4e8e\u5982\u679c\u5b58\u5728\u591a\u4e2aCMD\u884c, \u5219\u53ea\u6709\u6700\u540e\u4e00\u884c\u751f\u6548, \u8fd9\u4e2a\u6211\u4eec\u5e38\u7528\u6267\u884c\u9ed8\u8ba4\u7684shell\u547d\u4ee4\u7ed9\u8be5\u5bb9\u5668.<\/p>\n<p>5.LABEL<\/p>\n<p>LABEL &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; &#8230;<\/p>\n<p>\u4f8b:<\/p>\n<pre class=\"prettyprint lang-bsh\">LABEL \"com.example.vendor\"=\"ACME Incorporated\"\nLABEL com.example.label-with-value=\"foo\"\nLABEL version=\"1.0\"\nLABEL description=\"This text illustrates \\\nthat label-values can span multiple lines.\"<\/pre>\n<p>\u8fd9\u4e2a\u53ef\u4ee5\u7406\u89e3\u4e3a\u7ed9image\u4f20\u9001\u4e00\u4e2a\u952e\u503c\u5bf9.<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u67e5\u770b\u5df2Build\u597d\u7684image LABEL<\/p>\n<p># docker inspect<\/p>\n<p>6.EXPOSE<\/p>\n<p>EXPOSE &lt;port&gt; [&lt;port&gt;&#8230;]<\/p>\n<p>\u8fd9\u4e2a\u7528\u6765\u901a\u77e5\u5bb9\u5668\u5728\u67d0\u4e00\u5177\u4f53\u7aef\u53e3\u8fdb\u884c\u76d1\u542c, \u4f46\u4e0d\u4f1a\u6253\u5f00\u8be5\u7aef\u53e3, \u5982\u9700\u6253\u5f00\u8981\u5728\u521b\u5efa\u5bb9\u5668\u5bb9\u5668\u7684\u65f6\u5019\u914d\u5408-P\u53c2\u6570\u4f7f\u7528.<\/p>\n<p>7.ENV<\/p>\n<p>ENV &lt;key&gt; &lt;value&gt;<\/p>\n<p>ENV &lt;key&gt;=&lt;value&gt; &#8230;<\/p>\n<p>\u4f8b\u5982:<\/p>\n<pre class=\"prettyprint lang-bsh\">ENV myName=\"John Doe\" myDog=Rex\\ The\\ Dog \\\n       myCat=fluffy<\/pre>\n<p>\u76f8\u5f53\u4e8e\u7ed9\u955c\u50cf\u6dfb\u52a0\u73af\u5883\u53d8\u91cf.<\/p>\n<p>8.ADD<\/p>\n<p>ADD &lt;src&gt;&#8230; &lt;dest&gt;<\/p>\n<p>ADD [&#8220;&lt;src&gt;&#8221;,&#8230; &#8220;&lt;dest&gt;&#8221;] (\u8fd9\u79cd\u5199\u6cd5\u4f1a\u907f\u514d\u8def\u5f84\u540d\u542b\u6709\u7a7a\u683c\u800c\u62a5\u9519)<\/p>\n<p>ADD\u547d\u4ee4\u4f1acopy\u672c\u5730\u76ee\u5f55, \u6587\u4ef6\u6216\u8fdc\u7a0bURL\u5230\u5bb9\u5668\u76ee\u7684\u8def\u5f84, &lt;src&gt;, &lt;dest&gt;\u652f\u6301\u901a\u914d\u7b26\u548c\u7edd\u5bf9\u76f8\u5bf9\u8def\u5f84.<\/p>\n<p>\u4f8b\u5982:<\/p>\n<pre class=\"prettyprint lang-bsh\">ADD hom* \/mydir\/        # adds all files starting with \"hom\"\nADD hom?.txt \/mydir\/    # ? is replaced with any single character, e.g., \"home.txt\"\nADD test relativeDir\/   # adds \"test\" to `WORKDIR`\/relativeDir\/\nADD test \/absoluteDir   # adds \"test\" to \/absoluteDir<\/pre>\n<p>9.COPY<\/p>\n<p>COPY &lt;src&gt;&#8230; &lt;dest&gt;<\/p>\n<p>COPY [&#8220;&lt;src&gt;&#8221;,&#8230; &#8220;&lt;dest&gt;&#8221;] (\u8fd9\u79cd\u5199\u6cd5\u4f1a\u907f\u514d\u8def\u5f84\u540d\u542b\u6709\u7a7a\u683c\u800c\u62a5\u9519)<\/p>\n<p>\u672c\u8eab\u7528\u6cd5\u548cADD\u7c7b\u4f3c, \u552f\u72ec\u4e0d\u80fd\u4f7f\u7528\u8fdc\u7a0bURL<\/p>\n<p>10.VOLUME<\/p>\n<p>VOLUME [&#8220;\/data&#8221;]<br \/>\nVOLUME\u4f1a\u7ed9\u8be5image\u521b\u5efa\u4e00\u4e2a\u6302\u8f7d\u70b9.<\/p>\n<p>11.WORKDIR<\/p>\n<p>WORKDIR \/path\/to\/workdir<\/p>\n<p>\u987e\u540d\u601d\u4e49, \u6307\u5b9a\u4e00\u4e2a\u5f53\u524d\u7684\u5de5\u4f5c\u76ee\u5f55.<\/p>\n<p>12.Dockerfile\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint lang-bsh\"># Nginx\n#\n# VERSION               0.0.1\n\nFROM      ubuntu\nMAINTAINER Victor Vieux &lt;victor@docker.com&gt;\n\nLABEL Description=\"This image is used to start the foobar executable\" Vendor=\"ACME Products\" Version=\"1.0\"\nRUN apt-get update &amp;&amp; apt-get install -y inotify-tools nginx apache2 openssh-server\n\n\n# Firefox over VNC\n#\n# VERSION               0.3<\/pre>\n<pre class=\"prettyprint lang-bsh\">FROM ubuntu\n\n# Install vnc, xvfb in order to create a 'fake' display and firefox\nRUN apt-get update &amp;&amp; apt-get install -y x11vnc xvfb firefox\nRUN mkdir ~\/.vnc\n# Setup a password\nRUN x11vnc -storepasswd 1234 ~\/.vnc\/passwd\n# Autostart firefox (might not be the best way, but it does the trick)\nRUN bash -c 'echo \"firefox\" &gt;&gt; \/.bashrc'\n\nEXPOSE 5900\nCMD    [\"x11vnc\", \"-forever\", \"-usepw\", \"-create\"]\n<\/pre>\n<p>\u66f4\u591a\u8be6\u7ec6\u914d\u7f6e\u8bf7\u53c2\u8003:\u00a0<a href=\"http:\/\/www.showerlee.com\/archives\/1758\" rel=\"nofollow\">http:\/\/www.showerlee.com\/archives\/1758<\/a> \u7b2c10\u9879<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker\u53ef\u4ee5\u901a\u8fc7\u83b7\u53d6Dockerfile\u7f16\u5199\u7684\u547d\u4ee4\u81ea\u52a8Build\u51fa\u4e00\u4e2a\u65b0\u7684\u955c\u50cf,\u91cc\u9762\u7684Docker\u5185\u5efa\u547d\u4ee4\u4f1a\u5e2e\u52a9\u6211\u4eec\u5728\u5df2\u6709\u7684image\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9a\u5236image. \u8fd9\u91cc\u6211\u4eec\u5148\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e9b\u5e38\u7528Dockerfile\u7f16\u5199\u89c4\u8303. Docker\u914d\u7f6e\u4f20\u9001\u95e8:\u00a0http:\/\/www.showerlee.com\/archives\/1758 1.FROM FROM &lt;image&gt;:&lt;tag&gt; FROM\u4f1a\u4f7f\u7528\u5f53\u524d\u672c\u5730\u6216\u8005\u8fdc\u7a0bDocker\u4ed3\u5e93\u7684image, \u8fd9\u4e2a\u8981\u9996\u5148\u5199\u5230\u8be5\u811a\u672c\u7684\u7b2c\u4e00\u884c. \u4f8b: FROM centos67base\/apache:apache_base \u8fd9\u91cc\u4ee3\u8868\u6211\u4eec\u4f7f\u7528\u672c\u5730\u7684centos67base\/apache\u955c\u50cf. \u67e5\u770b\u672c\u5730\u7f13\u5b58\u955c\u50cf\u53ef\u4ee5\u4f7f\u7528 # docker images 2.MAINTAINER MAINTAINER &lt;name&gt; \u8fd9\u4e2a\u4f1a\u7ed9\u751f\u6210\u7684\u955c\u50cf\u521b\u5efa\u4e00\u4e2a\u4f5c\u8005\u540d [&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-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-95","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=95"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/95\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}