我在部署基于虚拟机的swarm时出现问题 - 我已按照官方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 node ...,docker service ...)我得到“来自守护进程的错误响应:404找不到页面”。
我做错了什么?
答案 0 :(得分:8)
您似乎正在尝试对旧的swarm mode使用新的docker swarm功能。
以下脚本创建一个HA Swarm集群,其中包含3个管理器和2个worker(使用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
列出群组成员
$ 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