我正在使用一个docker应用程序,其中已创建了一个用于测试docker swarm的试用存储库。我创建了一个docker-compose.yml文件并将其指向我的公共存储库。没有swam机制,它可以正常工作,但是当我将其放入swarm时,我没有任何反应。
docker-compose.yml:
version: "3"
services:
web:
image: repo-link
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:80"
networks:
- webnet
networks:
webnet:
我可以看到带有领导者的VM正常运行:
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 * virtualbox Running tcp://192.168.99.100:2376 v18.09.0
myvm2 - virtualbox Running tcp://192.168.99.101:2376 v18.09.0
PS命令:
docker stack ps project
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
mdb4b82nnkvu project_web.1 username/project:part1 myvm2 Running Running 13 minutes ago
shf6qmhzbtaq project_web.2 username/project:part1 myvm2 Running Running 13 minutes ago
ou5hy1uz6sh9 project_web.3 username/project:part1 myvm1 Running Running 13 minutes ago
kv4rvq1huxv4 project_web.4 username/project:part1 myvm2 Running Running 13 minutes ago
xtbc20orfd58 project_web.5 username/project:part1 myvm1 Running Running 13 minutes ago
使用的命令:
docker-machine create --driver virtualbox myvm1
docker-machine create --driver virtualbox myvm2
docker-machine ssh myvm1 "docker swarm init --advertise-addr <myvm1 ip>"
docker-machine ssh myvm2 "docker swarm join --token TOKEN 192.168.99.100:2377"
eval $(docker-machine env myvm1)
docker stack deploy -c docker-compose.yml project
然后,当我尝试时,我的虚拟机IP地址没有任何响应。