How to setup simple Docker Swarm Clustering with visual tools

本文介绍如何通过创建三台Docker虚拟机并配置为Swarm集群来实现负载均衡和服务扩展。详细步骤包括设置管理节点与工作节点、创建Nginx服务、发布端口、调整副本数量及安装可视化工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to setup simple Docker Swarm Clustering

1. Create 3 docker machines

docker-machine create -d virtualbox --engine-registry-mirror http://8ff28fe8.m.daocloud.io vm1
docker-machine create -d virtualbox --engine-registry-mirror http://8ff28fe8.m.daocloud.io vm2
docker-machine create -d virtualbox --engine-registry-mirror http://8ff28fe8.m.daocloud.io vm3

2. Enter vm1 and config it as manager

docker machine-ssh vm1
docker swarm  init --advertise-addr 192.168.99.101

3. Config vm2 & vm3 as worker

docker-machine ssh vm2
docker swarm join --token SWMTKN-1-3yelia5oyyxc8pn1z9tfb4a8j0liud5tljenquywu6ygiv7fk5-49xmnelykqja5fvft3bp
2892o 192.168.99.101:2377
docker-machine ssh vm3
docker swarm join --token SWMTKN-1-3yelia5oyyxc8pn1z9tfb4a8j0liud5tljenquywu6ygiv7fk5-49xmnelykqja5fvft3bp
2892o 192.168.99.101:2377

 

4. Create Nginx service as an example

 

docker service create --name=my_nginx nginx

5. Publish nginx 80 port

docker service update --publish-add 80 my_nginx

Then, you will see following page after accessing any server in the clustering with the port 3000, such as 

http://192.168.99.101:30000/ 

http://192.168.99.102:30000/ 

http://192.168.99.103:30000/ 

6. Scaling replicas

docker service scale my_nginx=5

docker service ps my_nginx

7. Install & config Docker Swarm Clustering visual tookkit (dockersamples/visualizer and Portainer)

7.1 Install dockersamples/visualizer

docker service create --name=viz --publish=8080:8080/tcp --constraint=node.role==manager --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock dockersamples/visualizer

http://192.168.99.101:8080

7.2 Install Portainer

docker service create \
    --name portainer \
    --publish 9000:9000 \
    --constraint 'node.role == manager' \
    --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \
    portainer/portainer \
    -H unix:///var/run/docker.sock

http://192.168.99.101:9000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yexianyi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值