{"id":583,"date":"2024-09-15T20:25:33","date_gmt":"2024-09-15T12:25:33","guid":{"rendered":"https:\/\/blog.ttf2.cn\/?p=583"},"modified":"2024-09-15T20:25:33","modified_gmt":"2024-09-15T12:25:33","slug":"docker%e4%bb%a3%e7%90%86","status":"publish","type":"post","link":"https:\/\/blog.ttf2.cn\/index.php\/2024\/09\/15\/docker%e4%bb%a3%e7%90%86\/","title":{"rendered":"Docker\u4ee3\u7406"},"content":{"rendered":"<h3><strong>Dockerd \u4ee3\u7406<\/strong><\/h3>\n<p>\u5728\u6267\u884c<code>docker pull<\/code>\u65f6\uff0c\u662f\u7531\u5b88\u62a4\u8fdb\u7a0b<code>dockerd<\/code>\u6765\u6267\u884c\u3002\u56e0\u6b64\uff0c\u4ee3\u7406\u9700\u8981\u914d\u5728<code>dockerd<\/code>\u7684\u73af\u5883\u4e2d\u3002\u800c\u8fd9\u4e2a\u73af\u5883\uff0c\u5219\u662f\u53d7<code>systemd<\/code>\u6240\u7ba1\u63a7\uff0c\u56e0\u6b64\u5b9e\u9645\u662f<code>systemd<\/code>\u7684\u914d\u7f6e\u3002<\/p>\n<pre><code class=\"language-javascript\">sudo mkdir -p \/etc\/systemd\/system\/docker.service.d\nsudo touch \/etc\/systemd\/system\/docker.service.d\/proxy.conf<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a<code>proxy.conf<\/code>\u6587\u4ef6\uff08\u53ef\u4ee5\u662f\u4efb\u610f<code>*.conf<\/code>\u7684\u5f62\u5f0f\uff09\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre><code class=\"language-javascript\">[Service]\nEnvironment=&quot;HTTP_PROXY=http:\/\/172.23.106.151:7897&quot;\nEnvironment=&quot;HTTPS_PROXY=http:\/\/172.23.106.151:7897&quot;\nEnvironment=&quot;NO_PROXY=localhost,127.0.0.1&quot;<\/code><\/pre>\n<p>\u5343\u4e07\u4e0d\u8981\u7528https\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01<\/p>\n<p>\u5176\u4e2d\uff0c<code>proxy.example.com:8080<\/code> \u8981\u6362\u6210\u53ef\u7528\u7684\u514d\u5bc6\u4ee3\u7406\u3002\u901a\u5e38\u4f7f\u7528 <code>cntlm<\/code> \u5728\u672c\u673a\u81ea\u5efa\u514d\u5bc6\u4ee3\u7406\uff0c\u53bb\u5bf9\u63a5\u516c\u53f8\u7684\u4ee3\u7406\u3002\u53ef\u53c2\u8003\u300a<strong>Linux<\/strong>\u4e0b\u5b89\u88c5\u914d\u7f6eCntlm \u4ee3\u7406\u300b\u3002<\/p>\n<p><strong>\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u5e76\u91cd\u542f Docker<\/strong>\uff1a<\/p>\n<pre><code class=\"language-shell\">sudo systemctl daemon-reload\nsudo systemctl restart docker<\/code><\/pre>\n<p><strong>\u9a8c\u8bc1\u914d\u7f6e<\/strong>\uff1a \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u786e\u8ba4\u73af\u5883\u53d8\u91cf\u5df2\u6b63\u786e\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-shell\">sudo systemctl show --property=Environment docker<\/code><\/pre>\n<h3><strong>Container \u4ee3\u7406<\/strong><\/h3>\n<p>\u5728<a href=\"https:\/\/cloud.tencent.com\/product\/tke?from_column=20065&amp;from=20065\">\u5bb9\u5668<\/a>\u8fd0\u884c\u9636\u6bb5\uff0c\u5982\u679c\u9700\u8981\u4ee3\u7406\u4e0a\u7f51\uff0c\u5219\u9700\u8981\u914d\u7f6e <code>~\/.docker\/config.json<\/code>\u3002\u4ee5\u4e0b\u914d\u7f6e\uff0c\u53ea\u5728<a href=\"https:\/\/cloud.tencent.com\/product\/tke?from_column=20065&amp;from=20065\">Docker<\/a> 17.07\u53ca\u4ee5\u4e0a\u7248\u672c\u751f\u6548\u3002<\/p>\n<pre><code class=\"language-javascript\">{\n &quot;proxies&quot;:\n {\n   &quot;default&quot;:\n   {\n     &quot;httpProxy&quot;: &quot;http:\/\/proxy.example.com:8080&quot;,\n     &quot;httpsProxy&quot;: &quot;http:\/\/proxy.example.com:8080&quot;,\n     &quot;noProxy&quot;: &quot;localhost,127.0.0.1,.example.com&quot;\n   }\n }\n}<\/code><\/pre>\n<p>\u8fd9\u4e2a\u662f\u7528\u6237\u7ea7\u7684\u914d\u7f6e\uff0c\u9664\u4e86 <code>proxies<\/code>\uff0c<code>docker login<\/code> \u7b49\u76f8\u5173\u4fe1\u606f\u4e5f\u4f1a\u5728\u5176\u4e2d\u3002\u800c\u4e14\u8fd8\u53ef\u4ee5\u914d\u7f6e\u4fe1\u606f\u5c55\u793a\u7684\u683c\u5f0f\u3001\u63d2\u4ef6\u53c2\u6570\u7b49\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u5bb9\u5668\u7684\u7f51\u7edc\u4ee3\u7406\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u5176\u8fd0\u884c\u65f6\u901a\u8fc7 <code>-e<\/code> \u6ce8\u5165 <code>http_proxy<\/code> \u7b49\u73af\u5883\u53d8\u91cf\u3002\u8fd9\u4e24\u79cd\u65b9\u6cd5\u5206\u522b\u9002\u5408\u4e0d\u540c\u573a\u666f\u3002<code>config.json<\/code> \u975e\u5e38\u65b9\u4fbf\uff0c\u9ed8\u8ba4\u5728\u6240\u6709\u914d\u7f6e\u4fee\u6539\u540e\u542f\u52a8\u7684\u5bb9\u5668\u751f\u6548\uff0c\u9002\u5408\u4e2a\u4eba\u5f00\u53d1\u73af\u5883\u3002\u5728CI\/CD\u7684\u81ea\u52a8\u6784\u5efa\u73af\u5883\u3001\u6216\u8005\u5b9e\u9645\u4e0a\u7ebf\u8fd0\u884c\u7684\u73af\u5883\u4e2d\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5c31\u4e0d\u592a\u5408\u9002\uff0c\u7528 <code>-e<\/code> \u6ce8\u5165\u8fd9\u79cd\u663e\u5f0f\u914d\u7f6e\u4f1a\u66f4\u597d\uff0c\u51cf\u8f7b\u5bf9\u6784\u5efa\u3001\u90e8\u7f72\u73af\u5883\u7684\u4f9d\u8d56\u3002\u5f53\u7136\uff0c\u5728\u8fd9\u4e9b\u73af\u5883\u4e2d\uff0c\u6700\u597d\u7528\u826f\u597d\u7684\u8bbe\u8ba1\u907f\u514d\u914d\u7f6e\u4ee3\u7406\u4e0a\u7f51\u3002<\/p>\n<h3><strong>Docker Build \u4ee3\u7406<\/strong><\/h3>\n<p>\u867d\u7136 <code>docker build<\/code> \u7684\u672c\u8d28\uff0c\u4e5f\u662f\u542f\u52a8\u4e00\u4e2a\u5bb9\u5668\uff0c\u4f46\u662f\u73af\u5883\u4f1a\u7565\u6709\u4e0d\u540c\uff0c\u7528\u6237\u7ea7\u914d\u7f6e\u65e0\u6548\u3002\u5728\u6784\u5efa\u65f6\uff0c\u9700\u8981\u6ce8\u5165 <code>http_proxy<\/code> \u7b49\u53c2\u6570\u3002<\/p>\n<pre><code class=\"language-javascript\">docker build . \\\n    --build-arg &quot;HTTP_PROXY=http:\/\/proxy.example.com:8080\/&quot; \\\n    --build-arg &quot;HTTPS_PROXY=http:\/\/proxy.example.com:8080\/&quot; \\\n    --build-arg &quot;NO_PROXY=localhost,127.0.0.1,.example.com&quot; \\\n    -t your\/image:tag<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u65e0\u8bba\u662f <code>docker run<\/code> \u8fd8\u662f <code>docker build<\/code>\uff0c\u9ed8\u8ba4\u662f\u7f51\u7edc\u9694\u7edd\u7684\u3002\u5982\u679c\u4ee3\u7406\u4f7f\u7528\u7684\u662f <code>localhost:3128<\/code> \u8fd9\u7c7b\uff0c\u5219\u4f1a\u65e0\u6548\u3002\u8fd9\u7c7b\u4ec5\u9650\u672c\u5730\u7684\u4ee3\u7406\uff0c\u5fc5\u987b\u52a0\u4e0a <code>--network host<\/code> \u624d\u80fd\u6b63\u5e38\u4f7f\u7528\u3002\u800c\u4e00\u822c\u5219\u9700\u8981\u914d\u7f6e\u4ee3\u7406\u7684\u5916\u90e8IP\uff0c\u800c\u4e14\u4ee3\u7406\u672c\u8eab\u8981\u5f00\u542f Gateway \u6a21\u5f0f\u3002<\/p>\n<h3><strong>\u91cd\u542f\u751f\u6548<\/strong><\/h3>\n<p>\u4ee3\u7406\u914d\u7f6e\u5b8c\u6210\u540e\uff0c<code>reboot<\/code> \u91cd\u542f\u5f53\u7136\u53ef\u4ee5\u751f\u6548\uff0c\u4f46\u4e0d\u91cd\u542f\u4e5f\u884c\u3002<\/p>\n<p><code>docker build<\/code> \u4ee3\u7406\u662f\u5728\u6267\u884c\u524d\u8bbe\u7f6e\u7684\uff0c\u6240\u4ee5\u4fee\u6539\u540e\uff0c\u4e0b\u6b21\u6267\u884c\u7acb\u5373\u751f\u6548\u3002Container \u4ee3\u7406\u7684\u4fee\u6539\u4e5f\u662f\u7acb\u5373\u751f\u6548\u7684\uff0c\u4f46\u662f\u53ea\u9488\u5bf9\u4ee5\u540e\u542f\u52a8\u7684 Container\uff0c\u5bf9\u5df2\u7ecf\u542f\u52a8\u7684 Container \u65e0\u6548\u3002<\/p>\n<p><code>dockerd<\/code> \u4ee3\u7406\u7684\u4fee\u6539\u6bd4\u8f83\u7279\u6b8a\uff0c\u5b83\u5b9e\u9645\u4e0a\u662f\u6539 <code>systemd<\/code> \u7684\u914d\u7f6e\uff0c\u56e0\u6b64\u9700\u8981\u91cd\u8f7d <code>systemd<\/code> \u5e76\u91cd\u542f <code>dockerd<\/code> \u624d\u80fd\u751f\u6548\u3002<\/p>\n<pre><code class=\"language-javascript\">sudo systemctl daemon-reload\nsudo systemctl restart docker<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dockerd \u4ee3\u7406 \u5728\u6267\u884cdocker pull\u65f6\uff0c\u662f\u7531\u5b88\u62a4\u8fdb\u7a0bdockerd\u6765\u6267\u884c\u3002\u56e0\u6b64\uff0c\u4ee3\u7406\u9700\u8981\u914d\u5728do &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.ttf2.cn\/index.php\/2024\/09\/15\/docker%e4%bb%a3%e7%90%86\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cDocker\u4ee3\u7406\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-583","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/posts\/583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/comments?post=583"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":587,"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/posts\/583\/revisions\/587"}],"wp:attachment":[{"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttf2.cn\/index.php\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}