{"id":934,"date":"2025-02-22T16:56:39","date_gmt":"2025-02-22T08:56:39","guid":{"rendered":"http:\/\/192.168.5.24\/?p=934"},"modified":"2025-02-22T16:56:40","modified_gmt":"2025-02-22T08:56:40","slug":"docker-swarm-%e9%9b%86%e7%be%a4%e9%83%a8%e7%bd%b2","status":"publish","type":"post","link":"https:\/\/bigvip.dpdns.org\/?p=934","title":{"rendered":"docker swarm \u96c6\u7fa4\u90e8\u7f72"},"content":{"rendered":"\n<p>         <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"739\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2025\/02\/image-8-1024x739.png\" alt=\"\" class=\"wp-image-938\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-8-1024x739.png 1024w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-8-300x217.png 300w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-8-768x555.png 768w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-8-816x589.png 816w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-8.png 1335w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Docker Compose\u662f\u4e00\u4e2a\u5728\u5355\u4e2a\u670d\u52a1\u5668\u6216\u4e3b\u673a\u4e0a\u521b\u5efa\u591a\u4e2a\u5bb9\u5668\u7684\u5de5\u5177\u3002<\/p>\n\n\n\n<p>         Docker swarm \u662fDocker\u516c\u53f8\u63a8\u51fa\u7684\u7528\u6765\u7ba1\u7406docker\u96c6\u7fa4\u7684\u5e73\u53f0\u3002\u5b83\u662f\u5c06\u4e00\u7fa4Docker\u5bbf\u4e3b\u673a\u53d8\u6210\u4e00\u4e2a\u5355\u4e00\u7684\u865a\u62df\u4e3b\u673a\uff0cSwarm\u4f7f\u7528\u6807\u51c6\u7684Docker API\u63a5\u53e3\u4f5c\u4e3a\u5176\u524d\u7aef\u7684\u8bbf\u95ee\u5165\u53e3\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>swManager<\/td><td>192.168.168.102<\/td><td><\/td><\/tr><tr><td>node1<\/td><td>192.168.168.103<\/td><td><\/td><\/tr><tr><td>node2<\/td><td>192.168.168.104<\/td><td><\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">\u8282\u70b9\u914d\u7f6e\u8868<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e00\u3001\u57fa\u7840\u73af\u5883\u914d\u7f6e\uff08\u6240\u6709\u8282\u70b9\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>1\u3001\u5404\u8282\u70b9\u6839\u636e\u8282\u70b9\u914d\u7f6e\u8868\u4fee\u6539\u81ea\u5df1\u7684\u4e3b\u673a\u540d\uff0c\u5e76\u4e14\u628a\u6240\u6709\u8282\u70b9\u7684\u4fe1\u606f\u6dfb\u52a0\u5230hosts\u6587\u4ef6\n2\u3001\u8bbe\u7f6essh\u4ecesw_Manager\u4e0a\u514d\u5bc6\u767b\u5f55\u5176\u5b83\u8282\u70b9<\/strong>\n<strong>3\u3001\u505a\u597d\u5404\u4e3b\u673a\u7684\u65f6\u95f4\u540c\u6b65\n4\u3001\u5173\u95ed\u9632\u706b\u5899\u3001\u5173\u95edselinux<\/strong>\n<strong>5\u3001\u5b89\u88c5docker\u5f15\u64ce<\/strong>\nyum -y install docker-ce\n<strong>6\u3001\u4fee\u6539docker\u955c\u50cf\u4ed3\u5e93\u5730\u5740<\/strong>\ncat &lt;&lt;EOF >\/etc\/docker\/daemon.json\n{\n\"insecure-registries\": &#91;\"192.168.5.24:5000\"],\n\"registry-mirrors\": &#91;\n    \"https:\/\/ccr.ccs.tencentyun.com\",\n    \"https:\/\/docker.rainbond.cc\",\n    \"https:\/\/elastic.m.daocloud.io\",\n    \"https:\/\/elastic.m.daocloud.io\",\n    \"https:\/\/docker.m.daocloud.io\",\n    \"https:\/\/gcr.m.daocloud.io\",\n    \"https:\/\/ghcr.m.daocloud.io\",\n    \"https:\/\/k8s-gcr.m.daocloud.io\",\n    \"https:\/\/k8s.m.daocloud.io\",\n    \"https:\/\/mcr.m.daocloud.io\",\n    \"https:\/\/nvcr.m.daocloud.io\",\n    \"https:\/\/quay.m.daocloud.io\"\n  ]\n}\n<strong>7\u3001\u8bbe\u7f6edocker\u5f15\u64ce\u81ea\u542f\u52a8<\/strong>\nsystemctl enable --now docker<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e8c\u3001\u914d\u7f6e\u96c6\u7fa4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>1\u3001\u521d\u59cb\u5316swarm<\/strong>\n\n&#91;root@swManager ~]# docker swarm init --listen-addr 192.168.168.102:2377\nSwarm initialized: current node (bukhx2jux7w2a9smr6l3b5arh) is now a manager.\n\nTo add a worker to this swarm, run the following command:\n\n    docker swarm join --token SWMTKN-1-18g572b7yi84rm8vlu4nsz17amf7ncagmlvjegkdeofn2fb629-4kqmthlbw2dd2xkpxwitzp7qw 192.168.168.102:2377\n\nTo add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.\n\n<strong>2\u3001\u6dfb\u52a0\u5de5\u4f5c\u8282\u70b9\u5230swarm\u96c6\u7fa4<\/strong>\n&#91;root@node1 ~]# docker swarm join --token SWMTKN-1-18g572b7yi84rm8vlu4nsz17amf7ncagmlvjegkdeofn2fb629-4kqmthlbw2dd2xkpxwitzp7qw 192.168.168.102:2377\nThis node joined a swarm as a worker.\n\n&#91;root@node2 ~]# docker swarm join --token SWMTKN-1-18g572b7yi84rm8vlu4nsz17amf7ncagmlvjegkdeofn2fb629-4kqmthlbw2dd2xkpxwitzp7qw 192.168.168.102:2377\nThis node joined a swarm as a worker.\n\n<strong>3\u3001\u67e5\u770b\u96c6\u7fa4\u8282\u70b9\u5217\u8868<\/strong>\n\n&#91;root@swManager ~]# docker node ls\nID                            HOSTNAME    STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION\ncznaxs2o5spp5n0vheen4wh5z     node1       Ready     Active                          26.1.3\nii8xz274uhx1jza0w8t2a6c40     node2       Ready     Active                          26.1.3\nbukhx2jux7w2a9smr6l3b5arh *   swManager   Ready     Active         Leader           26.1.3\n\n<strong>4\u3001\u56fe\u5f62\u5316\u67e5\u770b\u96c6\u7fa4<\/strong>\n\n&#91;root@swManager ~]# docker run -itd -p 8888:8080 -e HOST=192.168.168.102 -e PORT=8080 -v \/var\/run\/docker.sock:\/var\/run\/docker.sock --name visua 192.168.5.24:5000\/visualizer<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"644\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2025\/02\/image-9.png\" alt=\"\" class=\"wp-image-947\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-9.png 474w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-9-221x300.png 221w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>5\u3001\u670d\u52a1\u6d4b\u8bd5<\/strong>\n&#91;root@swManager ~]# docker service create --replicas 2 --mount \"type=bind,source=\/html,target=\/var\/www\/html\" --publish 8080:80 --name httpservice 192.168.5.24:5000\/centos-httpd:v1<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"644\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2025\/02\/image-10.png\" alt=\"\" class=\"wp-image-951\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-10.png 474w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-10-221x300.png 221w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n\n\n\n<p>\u670d\u52a1\u5df2\u7ecf\u8fd0\u884c\u5728\u591a\u4e2a\u8282\u70b9\u4e3b\u673a\u4e0a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>6\u3001docker stack<\/strong>\n\u901a\u8fc7docker service\u5df2\u7ecf\u53ef\u4ee5\u628a\u670d\u52a1\u4ee5\u591a\u4e2a\u5bb9\u5668\u526f\u672c\u7684\u5f62\u5f0f\u8fd0\u884c\u5728\u4e0d\u540c\u7684\u8282\u70b9\u4e3b\u673a\u4e0a\uff0c\u4f46\u662f\u65e0\u6cd5\u5f88\u597d\u7684\u4e00\u6b21\u6027\u8fd0\u884c\u591a\u4e2a\u6709\u5173\u8054\u7684\u670d\u52a1\uff0c\u800cdocker stack\u5c31\u53ef\u4ee5\u5f88\u597d\u7684\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker Compose\u662f\u4e00\u4e2a\u5728\u5355\u4e2a\u670d\u52a1\u5668\u6216\u4e3b\u673a\u4e0a\u521b\u5efa\u591a\u4e2a\u5bb9\u5668\u7684\u5de5\u5177\u3002 Docker swarm \u662fDoc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[20,36],"tags":[27,113],"class_list":["post-934","post","type-post","status-publish","format-aside","hentry","category-linux","category-36","tag-docker","tag-swarm","post_format-post-format-aside"],"_links":{"self":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=934"}],"version-history":[{"count":16,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/934\/revisions"}],"predecessor-version":[{"id":953,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/934\/revisions\/953"}],"wp:attachment":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}