gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:34:31 25 4
gpt4 key购买 nike

我在部署基于本地 virtualbox 的 swarm 时遇到问题 - 我已按照官方 docker 文档中有关使用 docker-machine 工具设置主/工作节点的说明进行操作。我已经在 dockerhub 上创建了 token ,并使用 --swarm (和 --swarm-master) 和 --swarm-discovery token://XXXX ...到目前为止一切顺利,两台机器正在运行,似乎注册为 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”获取状态,表明我有两个节点正在运行...但任何尝试运行任何其他 docker swarm 命令(docker 节点...、docker 服务...)我都会收到“来自守护程序的错误响应:404 页面未找到”。

我做错了什么?

最佳答案

您似乎正在尝试使用新的 swarm mode与旧版本的功能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

列出群组成员

$ 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

关于docker - 使用 docker-machine 设置 Swarm 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38666566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com