{"id":309,"date":"2023-04-15T16:50:24","date_gmt":"2023-04-15T08:50:24","guid":{"rendered":"https:\/\/www.bunnyism.com\/?p=309"},"modified":"2024-12-18T21:44:44","modified_gmt":"2024-12-18T13:44:44","slug":"docker-%e7%bd%91%e7%bb%9c%e4%b8%8b%e7%af%87","status":"publish","type":"post","link":"https:\/\/www.bunnyism.com\/?p=309","title":{"rendered":"docker \u7f51\u7edc\u4e0b\u7bc7"},"content":{"rendered":"<p>\u6211\u4eec\u540c\u4e3b\u673a\u5bb9\u5668\u5b9e\u73b0\u4e86\u901a\u4fe1 \u90a3\u4e48\u8de8\u4e3b\u673a\u600e\u4e48\u5b9e\u73b0\u901a\u4fe1~<\/p>\n<h2 class=\"lake-content\"><span class=\"ne-text\">macvlan\u5185\u6838\u6a21\u5757\u5b9e\u73b0\u8de8\u4e3b\u673a\u901a\u4fe1<\/span><\/h2>\n<h3 class=\"lake-content\"><span class=\"ne-text\">\u5224\u65adLinux\u5185\u6838\u662f\u5426\u652f\u6301macvlan\u6a21\u5757<\/span><\/h3>\n<blockquote><p>lsmod | grep macvlan<br \/>\nmodprobe macvlan<br \/>\nlsmod | grep macvlan<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"WhnnB\"><span class=\"ne-text\">\u4e24\u4e2a\u4e3b\u673a\u8282\u70b9\u521b\u5efa\u540c\u7f51\u6bb5\u7684\u81ea\u5b9a\u4e49\u7f51\u7edc\u7c7b\u578b<\/span><\/h3>\n<blockquote><p>docker network create -d macvlan &#8211;subnet 172.29.0.0\/16 &#8211;gateway 172.29.0.254 -o parent=eth0 <span class=\"ne-text\">custom<\/span>-macvlan<\/p><\/blockquote>\n<h3 id=\"c0jRW\"><span class=\"ne-text\">\u624b\u52a8\u5206\u914dIP\u5730\u5740<\/span><\/h3>\n<div class=\"lake-content\">\n<p id=\"c0jRW\"><span class=\"ne-text\">10.0.0.101\u8282\u70b9\u57fa\u4e8e\u81ea\u5b9a\u4e49\u7f51\u7edc\u542f\u52a8\u5bb9\u5668<\/span><\/p>\n<blockquote><p>docker container run &#8211;rm -it &#8211;name c1 &#8211;network <span class=\"ne-text\">custom<\/span>-macvlan &#8211;ip 172.29.0.101 alpine ifconfig<\/p><\/blockquote>\n<div class=\"lake-content\"><span class=\"ne-text\">10.0.0.102\u8282\u70b9\u57fa\u4e8e\u81ea\u5b9a\u4e49\u7f51\u7edc\u542f\u52a8\u5bb9\u5668<\/span><\/div>\n<blockquote>\n<div>docker container run &#8211;rm -it &#8211;name c2 &#8211;network <span class=\"ne-text\">custom<\/span>-macvlan &#8211;ip 172.29.0.102 alpine ifconfig<\/div>\n<\/blockquote>\n<div>\n<h3 class=\"lake-content\"><span class=\"ne-text\">\u4e24\u4e2a\u53ef\u4ee5\u8282\u70b9\u4e4b\u95f4\u7684\u5bb9\u5668<\/span><\/h3>\n<blockquote><p><span class=\"ne-text\">ping 172.29.0.102 -c 3<br \/>\n<\/span><\/p><\/blockquote>\n<div class=\"lake-content\">\n<blockquote>\n<p id=\"qGyus\"><span class=\"ne-text\">ping baidu.com -c 3 # \u65e0\u6cd5\u8bbf\u95ee\u5916\u7f51<\/span><\/p>\n<div class=\"lake-content\">\n<p id=\"uf465c243\" class=\"ne-p\"><span class=\"ne-text\">#\u6211\u4eec\u9700\u8981\u624b\u52a8\u5206\u914dIP\u5730\u5740\uff0c\u65e0\u6cd5\u8054\u7f51\u7684\u95ee\u9898\uff0c\u53ea\u9700\u8981\u4f7f\u7528&#8221;docker network connect&#8221;\u91cd\u65b0\u5206\u914d\u4e00\u5757\u7f51\u5361\u5373\u53ef\u89e3\u51b3<\/span><\/p>\n<\/div>\n<\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"J9UwV\"><span class=\"ne-text\">macvlan\u7684\u4f18\u7f3a\u70b9<\/span><\/h3>\n<p style=\"padding-left: 40px;\"><em><strong>\u4f18\u70b9<\/strong><\/em><\/p>\n<blockquote><p>&#8211; docker\u539f\u751f\u652f\u6301\uff0c\u65e0\u9700\u5b89\u88c5\u989d\u5916\u63d2\u4ef6\uff0c\u914d\u7f6e\u8d77\u6765\u76f8\u5bf9\u7b80\u5355\u3002<br \/>\n&#8211; \u9002\u5408\u5c0f\u89c4\u6a21docker\u73af\u5883\uff0c\u4f8b\u5982\u53ea\u67091-3\u53f0\uff0c\u5982\u679c\u670d\u52a1\u5668\u8fc7\u591a\uff0c\u624b\u52a8\u5206\u914dIP\u5730\u5740\u53ef\u80fd\u4f1a\u65e0\u5f62\u4e4b\u95f4\u589e\u52a0\u5de5\u4f5c\u91cf;<\/p><\/blockquote>\n<p style=\"padding-left: 40px;\"><em><strong>\u7f3a\u70b9<\/strong><\/em><\/p>\n<blockquote><p>&#8211; \u9700\u8981\u624b\u52a8\u5206\u914dIP\u5730\u5740\uff0c\u5982\u679c\u8ba9\u5176\u81ea\u52a8\u5206\u914dIP\u5730\u5740\u53ef\u80fd\u4f1a\u5b58\u5728\u591a\u4e2a\u4e3b\u673a\u81ea\u52a8\u5206\u914d\u7684IP\u5730\u5740\u51b2\u7a81\u7684\u60c5\u51b5\uff0c\u5230\u65f6\u5019\u8fd8\u9700\u8981\u4eba\u5de5\u4ecb\u5165\u7ef4\u62a4;<br \/>\n&#8211; \u672c\u673a\u76f8\u540c\u7f51\u7edc(\u672c\u6848\u4f8b\u4e3a&#8221;<span class=\"ne-text\">custom<\/span>-macvlan&#8221;)\u7684\u5bb9\u5668\u4e4b\u95f4\u76f8\u4e92\u901a\u4fe1\u6ca1\u95ee\u9898\uff0c\u8de8\u4e3b\u673a\u4e4b\u95f4\u7684\u5bb9\u5668\u8fdb\u884c\u901a\u4fe1\u4e5f\u6ca1\u95ee\u9898\uff0c\u4f46\u5bb9\u5668\u65e0\u6cd5\u4e0e\u5bbf\u4e3b\u673a\u4e4b\u95f4\u8fdb\u884c\u901a\u4fe1\uff0c\u4e5f\u65e0\u6cd5\u8fde\u63a5\u5230\u5916\u7f51<br \/>\n&#8211;\u00a0 macvlan\u9700\u8981\u7ed1\u5b9a\u4e00\u5757\u7269\u7406\u7f51\u5361\uff0c\u82e5\u7f51\u5361\u5df2\u7ecf\u88ab\u7ed1\u5b9a\uff0c\u5219\u65e0\u6cd5\u521b\u5efa;<\/p><\/blockquote>\n<h2 class=\"lake-content\"><span class=\"ne-text\">overlay\u5b9e\u73b0\u5bb9\u5668\u8de8\u4e3b\u673a\u7f51\u7edc\u4e92\u8054 \uff08\u4e3b\u8282\u70b910.0.0.101\uff09<br \/>\n<\/span><\/h2>\n<p>\u642d\u5efa\u4e00\u4e2aconsul\u5c06\u4e24\u4e2a\u8282\u70b9\u5bb9\u5668\u52a0\u5165\u96c6\u7fa4 \u5b83\u4f1a\u66f4\u65b0\u914d\u7f6e\u5230\u96c6\u7fa4\u4e2d\u7684\u6240\u4ee5\u8282\u70b9<\/p>\n<p>\u5148\u5728\u4e24\u4e2a\u4e3b\u673a\u8282\u70b9\u91cc\u521b\u5efa\u4e24\u4e2aconsul\u5bb9\u5668<\/p>\n<div class=\"lake-content\">\n<blockquote>\n<p id=\"u07a0c068\" class=\"ne-p\"><span class=\"ne-text\">#\u90e8\u7f72consul\u670d\u52a1\uff0c\u5982\u679c\u4f60\u7684\u7f51\u5361\u540d\u79f0\u4e0d\u662fens33\uff0c\u9700\u8981\u4fee\u6539\uff0c\u6bd4\u5982eth0 \u76f8\u5f53\u4e8e\u7f51\u5361\u7ed1\u5b9a<\/span><\/p>\n<p class=\"ne-p\">docker run -d &#8211;network host &#8211;restart always &#8211;name=dev-consul -e CONSUL_BIND_INTERFACE=eth0 consul:1.12.3<\/p>\n<\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"ps7g2\"><span class=\"ne-text\">\u67e5\u770b\u670d\u52a1\u7aef\u7684\u7aef\u53e3<\/span><\/h3>\n<blockquote><p>ss -ntl | grep 8500<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"bkktC\"><span class=\"ne-text\">\u5982\u679c\u60f3\u8981\u642d\u5efa\u96c6\u7fa4\u5c31\u6267\u884c\u4e0b\u97623\u4e2a\u547d\u4ee4\u00a0 \u53ef\u9009\u64cd\u4f5c<\/span><\/h3>\n<blockquote><p># docker run -d -e CONSUL_BIND_INTERFACE=eth0 consul:1.12.3 &#8211;restart always agent -dev -join=10.0.0.101<br \/>\n# docker run -d -e CONSUL_BIND_INTERFACE=eth0 consul:1.12.3 &#8211;restart always agent -dev -join=10.0.0.101<br \/>\n# docker exec -t dev-consul consul members<\/p><\/blockquote>\n<h3>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<span class=\"ne-text\">\uff08102\u5b50\u8282\u70b9\uff09<\/span><\/h3>\n<blockquote><p>vim \/etc\/docker\/daemon.json<\/p>\n<p>{<\/p>\n<p>#\u8fd9\u4e2a\u9009\u9879\u6307\u5b9a\u4e86\u4e00\u4e2a\u5916\u90e8\u7684\u670d\u52a1\u6ce8\u518c\u4e2d\u5fc3\u6216\u914d\u7f6e\u5b58\u50a8\u7cfb\u7edf\u7684\u4f4d\u7f6e<br \/>\n&#8220;cluster-store&#8221;: &#8220;consul:\/\/10.0.0.101:8500&#8221;,<\/p>\n<p>\u8fd9\u4e2a\u9009\u9879\u7528\u4e8e\u6307\u5b9a\u5f53\u524d\u8282\u70b9\u5bf9\u5916\u901a\u544a\u81ea\u5df1\u7684\u5730\u5740\uff0c\u5373\u5176\u4ed6\u6210\u5458\u5982\u4f55\u901a\u8fc7\u7f51\u7edc\u4e0e\u8fd9\u4e2a\u8282\u70b9\u8fdb\u884c\u901a\u4fe1<br \/>\n&#8220;cluster-advertise&#8221;: &#8220;10.0.0.102:9999&#8221;<br \/>\n}<\/p><\/blockquote>\n<h3>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<span class=\"ne-text\">\uff08103\u5b50\u8282\u70b9\uff09<\/span><\/h3>\n<blockquote><p>vim \/etc\/docker\/daemon.json<\/p>\n<p>{<br \/>\n&#8220;cluster-store&#8221;: &#8220;consul:\/\/10.0.0.101:8500&#8221;,<br \/>\n&#8220;cluster-advertise&#8221;: &#8220;10.0.0.103:9969&#8221;<br \/>\n}<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"fhwY8\"><span class=\"ne-text\">\u8bbf\u95ee\u670d\u52a1\u7aef\u8282\u70b9webui\u5730\u5740<\/span><\/h3>\n<blockquote><p>http:\/\/10.0.0.101:8500\/ui\/dc1\/kv\/docker\/nodes\/<\/p><\/blockquote>\n<div class=\"lake-content\">\n<h3 id=\"t90T1\"><span class=\"ne-text\">\u4efb\u610f\u5ba2\u6237\u7aef\u8282\u70b9\u521b\u5efa\u7f51\u7edc\uff0c\u5176\u4ed6\u5ba2\u6237\u7aef\u4f1a\u901a\u8fc7consul\u6765\u5b9e\u65f6\u540c\u6b65\u914d\u7f6e\u54df \u5982102 \u521b\u5efa\u7f51\u7edc<\/span><\/h3>\n<blockquote><p>docker network create -d overlay &#8211;subnet 172.30.0.0\/16 &#8211;gateway 172.30.0.254 <span class=\"ne-text\">custom<\/span>-overlay<\/p>\n<p>#\u5176\u4ed6\u8282\u70b9\u5c06\u540c\u6b65\u521b\u5efa\u81ea\u5b9a\u4e49\u7f51\u7edc<\/p><\/blockquote>\n<h3>\u8282\u70b9\u95f4\u901a\u4fe1\u6d4b\u8bd5<\/h3>\n<blockquote><p>#\u8282\u70b91<\/p>\n<p>docker container run &#8211;rm -it &#8211;name cc1 &#8211;network <span class=\"ne-text\">custom<\/span>-overlay alpine<\/p>\n<p>#\u8282\u70b92<\/p>\n<p>docker container run &#8211;rm -it &#8211;name cc2 &#8211;network <span class=\"ne-text\">custom<\/span>-overlay alpine<\/p>\n<p>#\u8282\u70b93<\/p>\n<p>docker container run &#8211;rm -it &#8211;name cc3 &#8211;network <span class=\"ne-text\">custom<\/span>-overlay alpine<\/p>\n<p>#\u8fdb\u5165\u4efb\u610f\u5bb9\u5668 ping \u53d1\u73b0 \u8282\u70b9\u95f4\u90fd\u53ef\u4e92\u76f8\u901a\u4fe1<\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u540c\u4e3b\u673a\u5bb9\u5668\u5b9e\u73b0\u4e86\u901a\u4fe1 \u90a3\u4e48\u8de8\u4e3b\u673a\u600e\u4e48\u5b9e\u73b0\u901a\u4fe1~ macvlan\u5185\u6838\u6a21\u5757\u5b9e\u73b0\u8de8\u4e3b\u673a\u901a\u4fe1 \u5224\u65adLinux\u5185\u6838\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":195,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-309","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\/309","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=309"}],"version-history":[{"count":36,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions"}],"predecessor-version":[{"id":345,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions\/345"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/media\/195"}],"wp:attachment":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}