一尘不染

使用docker-machine设置Swarm的麻烦

docker

我在部署基于本地virtualbox的群集时遇到问题-我已按照官方docker文档中的说明使用docker-
machine工具设置主节点/工作节点。我已经在dockerhub上创建了令牌,并将–swarm(和–swarm-master)与–swarm-
discovery token:// XXXX一起使用…到目前为止,到目前为止,两台机器都在运行,似乎已注册为Swarm master和工人:

spaceback@brutus:~$ docker-machine ls
NAME           ACTIVE      DRIVER       STATE     URL                         SWARM                   DOCKER    ERRORS
swarm-master   * (swarm)   virtualbox   Running   tcp://192.168.99.100:2376   swarm-master (master)   v1.12.0   
swarm-node1    -           virtualbox   Running   tcp://192.168.99.101:2376   swarm-master            v1.12.0   
spaceback@brutus:~$ docker run --rm swarm list token://[....]
192.168.99.101:2376
192.168.99.100:2376

然后使用“ eval $(docker-machine env –swarm swarm-master)”设置正确的环境值后,我可以使用“ docker
info”获得状态,表明我有两个正在运行的节点,但是尝试运行任何其他docker
swarm命令(docker节点…,docker服务…),我得到“来自守护程序的错误响应:找不到404页面”。

我究竟做错了什么?


阅读 379

收藏
2020-06-17

共1个答案

一尘不染

看来您正在尝试对旧的docker
swarm
使用新的swarm模式功能。

以下脚本使用3个管理器和2个工作器(使用Docker 1.12.0)创建一个HA Swarm集群:

#=========================
# Creating cluster members
#=========================
docker-machine create --driver virtualbox node1
docker-machine create --driver virtualbox node2
docker-machine create --driver virtualbox node3
docker-machine create --driver virtualbox node4
docker-machine create --driver virtualbox node5

#===============
# Starting swarm
#===============
MANAGER_IP=$(docker-machine ip node1)

docker-machine ssh node1 docker swarm init --advertise-addr $MANAGER_IP

#===============
# Adding members
#===============
MANAGER_TOKEN=$(docker-machine ssh node1 docker swarm join-token --quiet manager)
WORKER_TOKEN=$(docker-machine ssh node1 docker swarm join-token --quiet worker)

docker-machine ssh node2 docker swarm join --token $MANAGER_TOKEN $MANAGER_IP:2377
docker-machine ssh node3 docker swarm join --token $MANAGER_TOKEN $MANAGER_IP:2377
docker-machine ssh node4 docker swarm join --token $WORKER_TOKEN  $MANAGER_IP:2377
docker-machine ssh node5 docker swarm join --token $WORKER_TOKEN  $MANAGER_IP:2377

列出群成员

$ docker-machine ssh node1 docker node ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
4s0mrh2u4sa2p260ung8ipb0m *  node1     Ready   Active        Leader
5ra7b8cwarpcpa47p2gq2ecxs    node2     Ready   Active        Reachable
66t3pq66ynlvyl3do6lpn9kzb    node3     Ready   Active        
7k5n1id2q6yncqjbv7l8ec0r5    node5     Ready   Active        
833e4ya58hq62epplreyvwtnm    node4     Ready   Active

创建服务

$ docker-machine ssh node1 docker service create --name web --replicas=10 -p 30000:80 nginx

$ docker-machine ssh node1 docker service ps web
ID                         NAME    IMAGE  NODE   DESIRED STATE  CURRENT STATE           ERROR
2fxy4n57p8ot3mn0kws96pnuk  web.1   nginx  node1  Running        Running 30 seconds ago  
cmm1s3h8ds7tmppf7pwvl5zxw  web.2   nginx  node5  Running        Running 6 seconds ago   
7ixgtqlz049ggi90363js088b  web.3   nginx  node1  Running        Running 30 seconds ago  
4o1e2wkh0x4rp8h9o73as8drf  web.4   nginx  node3  Running        Running 22 seconds ago  
6lufnzzddljlw0lnu0qyftzh6  web.5   nginx  node3  Running        Running 22 seconds ago  
49g43g23t4r9lpmitfs4uu1j6  web.6   nginx  node2  Running        Running 3 seconds ago   
43dopngi08licw4xttipnfdb6  web.7   nginx  node2  Running        Running 3 seconds ago   
8d47dvmokf65xb271fyk3jlbu  web.8   nginx  node4  Running        Running 7 seconds ago   
2t56edm3k4x98yjkvgamyq6v4  web.9   nginx  node5  Running        Running 6 seconds ago   
byij5j5pom1t3elu2ydteasg7  web.10  nginx  node4  Running        Running 7 seconds ago
2020-06-17