使用 docker-machine 设置 Swarm 时出现问题

Troubles using docker-machine to setup Swarm

我在部署基于本地 virtualbox 的 swarm 时遇到问题 - 我已按照官方 docker 文档中有关使用 docker 机器工具设置 master/worker 节点的说明进行操作。我已经在 dockerhub 上创建了令牌,并使用了 --swarm(和 --swarm-master)和 --swarm-discovery token://XXXX ...到目前为止一切顺利,两台机器 运行ning,貌似注册为Swarm master和worker:

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" 获取状态,表明我有两个节点 运行ning... 但是任何尝试 运行 任何其他 docker swarm 命令(docker 节点...,docker 服务...)我得到 "Error response from daemon: 404 page not found".

我做错了什么?

您似乎正在尝试使用新的 swarm mode features against the older docker swarm

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

#=========================
# 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

列出 swarm 成员

$ 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