{"id":642,"date":"2023-02-26T13:34:24","date_gmt":"2023-02-26T05:34:24","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=642"},"modified":"2023-04-29T19:58:28","modified_gmt":"2023-04-29T11:58:28","slug":"docker-image-and-container","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/docker-image-and-container\/","title":{"rendered":"Docker\u955c\u50cf\u548c\u5bb9\u5668"},"content":{"rendered":"<h2>\u7406\u89e3\u955c\u50cf\u548c\u5bb9\u5668<\/h2>\n<p>Docker\u5f15\u64ce\u63d0\u4f9b\u5b9e\u73b0\u955c\u50cf\u548c\u5bb9\u5668\u7684\u6838\u5fc3\u6280\u672f\u3002\u955c\u50cf\u662f\u5728\u8fd0\u884c\u65f6\u4f7f\u7528\u7684\u6587\u4ef6\u7cfb\u7edf\u548c\u53c2\u6570\u96c6\uff0c\u5b83\u6ca1\u6709\u72b6\u6001\u5e76\u4e14\u6c38\u8fdc\u4e0d\u4f1a\u6539\u53d8\u3002\u5bb9\u5668\u662f\u955c\u50cf\u7684\u8fd0\u884c\u5b9e\u4f8b\u3002\u5f53\u8fd0\u884c\u547d\u4ee4\u65f6\uff0cDocker\u5f15\u64ce\uff1a<\/p>\n<p><!-- more --><\/p>\n<ul>\n<li>\u68c0\u67e5\u662f\u5426\u6709\u955c\u50cf\u6587\u4ef6<\/li>\n<li>\u4eceDocker Hub\u4e0b\u8f7d\u6620\u50cf<\/li>\n<li>\u5c06\u955c\u50cf\u52a0\u8f7d\u5230\u5bb9\u5668\u4e2d\u5e76\u201c\u8fd0\u884c\u201d\u5b83<\/li>\n<\/ul>\n<p>Docker Hub\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/hub.docker.com\/\">https:\/\/hub.docker.com\/<\/a><\/p>\n<h2>\u8fd0\u884c whalesay\u955c\u50cf<\/h2>\n<p>Docker Hub \u4e3b\u9875\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/hub.docker.com\/r\/docker\/whalesay\/\">https:\/\/hub.docker.com\/r\/docker\/whalesay\/<\/a><\/p>\n<pre><code class=\"language-shell\">$ sudo docker run docker\/whalesay cowsay boo\nUnable to find image &#039;docker\/whalesay:latest&#039; locally\nlatest: Pulling from docker\/whalesay\ne190868d63f8: Pull complete \n909cd34c6fd7: Pull complete \n0b9bfabab7c1: Pull complete \na3ed95caeb02: Pull complete \n00bf65475aba: Pull complete \nc57b6bcc83e3: Pull complete \n8978f6879e2f: Pull complete \n8eed3712d2cf: Pull complete \nDigest: sha256:178598e51a26abbc958b8a2e48825c90bc22e641de3d31e18aaf55f3258ba93b\nStatus: Downloaded newer image for docker\/whalesay:latest\n _____ \n&lt; boo &gt;\n ----- \n    \\\n     \\\n      \\     \n                    ##        .            \n              ## ## ##       ==            \n           ## ## ## ##      ===            \n       \/&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;___\/ ===        \n  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ \/  ===- ~~~   \n       \\______ o          __\/            \n        \\    \\        __\/             \n          \\____\\______\/ \n$ docker images  \/\/\u663e\u793a\u6240\u6709\u955c\u50cf\nREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE\nhello-world         latest              48b5124b2768        2 months ago        1.84 kB\ndocker\/whalesay     latest              6b362a9f73eb        22 months ago       247 MB\n$ sudo docker run docker\/whalesay cowsay Hello, Joe.Ye  \/\/\u4fee\u6539\u53c2\u6570\u91cd\u65b0\u8fd0\u884c\u955c\u50cf\n _______________ \n&lt; Hello, Joe.Ye &gt;\n --------------- \n    \\\n     \\\n      \\     \n                    ##        .            \n              ## ## ##       ==            \n           ## ## ## ##      ===            \n       \/&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;___\/ ===        \n  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ \/  ===- ~~~   \n       \\______ o          __\/            \n        \\    \\        __\/             \n          \\____\\______\/<\/code><\/pre>\n<h2>\u6784\u5efa\u955c\u50cf<\/h2>\n<h3>\u521b\u5efa\u4e00\u4e2aDockerfile<\/h3>\n<p>A Dockerfile is a recipe which describes the files, environment, and commands that make up an image.<\/p>\n<pre><code>$ mkdir mydockerbuild\n$ cd mydockerbuild\n$ vim Dockerfile\n    FROM docker\/whalesay:latest\n    MAINTAINER Joe.Ye &lt;yezhou@yezhou.org&gt;\n\n    RUN apt-get -y update &amp;&amp; apt-get install -y fortunes\n    RUN git clone https:\/\/github.com\/ruanyf\/fortunes.git\n    RUN cp fortunes\/data\/* \/usr\/share\/games\/fortunes\/\n    CMD \/usr\/games\/fortune -a | cowsay<\/code><\/pre>\n<blockquote>\n<p>\u65e9\u57281979\u5e74\uff0c\u5c31\u6709\u4eba\u5199\u4e86\u4e00\u4e2a\u53eb\u505a fortune \u7684\u5c0f\u7a0b\u5e8f\u3002\u5728\u547d\u4ee4\u884c\u4e0b\u8f93\u5165fortune\uff0c\u5c31\u4f1a\u8df3\u51fa\u4e00\u53e5\u3002<\/p>\n<\/blockquote>\n<p>fortune\u4e2d\u6587\u683c\u8a00\u5e93\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/ruanyf\/fortunes\">https:\/\/github.com\/ruanyf\/fortunes<\/a><\/p>\n<pre><code>$ git clone https:\/\/github.com\/ruanyf\/fortunes.git\n$ sudo cp fortunes\/data\/* \/usr\/share\/games\/fortunes\/<\/code><\/pre>\n<h3>\u4eceDockerfile\u7f16\u8bd1\u955c\u50cf<\/h3>\n<pre><code>$ sudo docker build -t docker-whale .<\/code><\/pre>\n<ul>\n<li>-t \u4e3a\u955c\u50cf\u6307\u5b9atag<\/li>\n<li>. \u8868\u793a\u5f53\u524d\u76ee\u5f55<\/li>\n<\/ul>\n<pre><code>$ sudo docker images\nREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE\ndocker-whale        latest              8fff85eaeacf        4 minutes ago       256 MB\n&lt;none&gt;              &lt;none&gt;              d3ab35128e41        9 minutes ago       247 MB\nhello-world         latest              48b5124b2768        2 months ago        1.84 kB\ndocker\/whalesay     latest              6b362a9f73eb        22 months ago       247 MB\n\n$ docker run docker-whale  \/\/\u8fd0\u884c<\/code><\/pre>\n<h2>\u521b\u5efa Docker Hub \u8d26\u53f7\u548c\u4ed3\u5e93\u5e76\u53d1\u5e03\u955c\u50cf<\/h2>\n<p>\u6ce8\u518c\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/hub.docker.com\/register\/\">https:\/\/hub.docker.com\/register\/<\/a><\/p>\n<h3>Tag and push the image<\/h3>\n<pre><code>$ sudo docker images  \/\/\u627e\u5230 docker-whale\u955c\u50cf\u7684Tag\nREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE\ndocker-whale        latest              8fff85eaeacf        33 minutes ago      256 MB\n&lt;none&gt;              &lt;none&gt;              d3ab35128e41        38 minutes ago      247 MB\nhello-world         latest              48b5124b2768        2 months ago        1.84 kB\ndocker\/whalesay     latest              6b362a9f73eb        22 months ago       247 MB\n$ sudo docker tag 8fff85eaeacf yezhou\/docker-whale:latest  \/\/Tag the docker-whale image\n$ sudo docker images  \/\/\u786e\u8ba4 docker-whale\u955c\u50cf\u5df2\u88abTagged\nREPOSITORY            TAG                 IMAGE ID            CREATED             SIZE\ndocker-whale          latest              8fff85eaeacf        37 minutes ago      256 MB\nyezhou\/docker-whale   latest              8fff85eaeacf        37 minutes ago      256 MB\n&lt;none&gt;                &lt;none&gt;              d3ab35128e41        41 minutes ago      247 MB\nhello-world           latest              48b5124b2768        2 months ago        1.84 kB\ndocker\/whalesay       latest              6b362a9f73eb        22 months ago       247 MB<\/code><\/pre>\n<h3>\u767b\u5f55\u5e76\u53d1\u5e03\u955c\u50cf<\/h3>\n<pre><code>$ sudo docker login\nUsername: yezhou\nPassword: \nLogin Succeeded\n$ sudo docker push yezhou\/docker-whale\ntime=&quot;2017-03-21T20:22:50+08:00&quot; level=info msg=&quot;Unable to use system certificate pool: crypto\/x509: system root pool is not available on Windows&quot;\nThe push refers to a repository [docker.io\/yezhou\/docker-whale]\nc04df8c4e2c7: Pushed\n0f52c7601381: Layer already exists\n7e86c6a40f66: Pushed\n5f70bf18a086: Layer already exists\nd061ee1340ec: Layer already exists\nd511ed9e12e1: Layer already exists\n091abc5148e4: Layer already exists\nb26122d57afa: Layer already exists\n37ee47034d9b: Layer already exists\n528c8710fd95: Layer already exists\n1154ba695078: Pushed\nlatest: digest: sha256:090cbc4196976c9a575ccc78150f0460593c709c3e3fa5cbc32e12fa088f4ab9 size: 3036<\/code><\/pre>\n<h3>\u62c9\u53d6\u65b0\u53d1\u5e03\u7684\u955c\u50cf<\/h3>\n<pre><code>docker rmi id  \/\/\u6839\u636eid\u5220\u9664\u955c\u50cf\ndocker rm  \/\/\u5220\u9664\u5bb9\u5668<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7406\u89e3\u955c\u50cf\u548c\u5bb9\u5668 Docker\u5f15\u64ce\u63d0\u4f9b\u5b9e\u73b0\u955c\u50cf\u548c\u5bb9\u5668\u7684\u6838\u5fc3\u6280\u672f\u3002\u955c\u50cf\u662f\u5728\u8fd0\u884c\u65f6\u4f7f\u7528\u7684\u6587\u4ef6\u7cfb\u7edf\u548c\u53c2\u6570\u96c6\uff0c\u5b83\u6ca1\u6709\u72b6\u6001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[179],"tags":[],"class_list":["post-642","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=642"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/642\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}