并刚刚跑完docker stack deploy --compose-file docker-stack.yml vote
。
我得到的输出表明容器正在运行:
cchilders:~/tutorials/docker/self-paced-training-beginner-linux-containers/example-voting-app (master)
$ docker stack services vote
ID NAME MODE REPLICAS IMAGE
27yqy6x84gyk vote_visualizer replicated 1/1 manomarks/visualizer:latest
ism6o6nsn9or vote_db replicated 1/1 postgres:9.4
lcklesojqejm vote_result replicated 2/2 dockersamples/examplevotingapp_result:before
p0c6q08t8xpo vote_worker replicated 1/1 dockersamples/examplevotingapp_worker:latest
we85p3f2fx2z vote_redis replicated 2/2 redis:alpine
zv145asbefcu vote_vote replicated 2/2 dockersamples/examplevotingapp_vote:before
教程说你现在可以访问端口 5000、5001 等,但即使我的容器在堆栈中运行,它们也会全部失败。我得到
This site can’t be reached
localhost refused to connect.
Search Google for localhost 5001
ERR_CONNECTION_REFUSED
在 Chrome 中尝试以页面形式打开这些内容时,例如localhost:5000
他们建议您使用的文件是
version: "3"
services:
redis:
image: redis:alpine
ports:
- "6379"
networks:
- frontend
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
db:
image: postgres:9.4
volumes:
- db-data:/var/lib/postgresql/data
networks:
- backend
deploy:
placement:
constraints: [node.role == manager]
vote:
image: dockersamples/examplevotingapp_vote:before
ports:
- 5000:80
networks:
- frontend
depends_on:
- redis
deploy:
replicas: 2
update_config:
parallelism: 2
restart_policy:
condition: on-failure
result:
image: dockersamples/examplevotingapp_result:before
ports:
- 5001:80
networks:
- backend
depends_on:
- db
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure
worker:
image: dockersamples/examplevotingapp_worker
networks:
- frontend
- backend
deploy:
mode: replicated
replicas: 1
labels: [APP=VOTING]
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
visualizer:
image: manomarks/visualizer
ports:
- "8080:8080"
stop_grace_period: 1m30s
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
frontend:
backend:
volumes:
db-data:
唯一的步骤是
docker swarm init --advertise-addr $(docker-machine ip)
docker stack deploy --compose-file docker-stack.yml vote
从保存的example-voting-app
目录中docker-stack.yml
为什么这些端口在服务正在运行时不会打开网页vote
?谢谢
答案1
当主服务器被克隆并docker-compose up
运行时result
,无法构建容器:
Building result
Step 1/11 : FROM node:5.11.0-slim
---> cb888ea932ad
Step 2/11 : WORKDIR /app
---> Using cache
---> d6501817bc62
Step 3/11 : RUN npm install -g nodemon
---> Using cache
---> 33415c41649c
Step 4/11 : ADD package.json /app/package.json
---> Using cache
---> a1cf6be1ea33
Step 5/11 : RUN npm config set registry http://registry.npmjs.org
---> Using cache
---> 4d1f7b8fdd8b
Step 6/11 : RUN npm install && npm ls
---> Using cache
---> c57c08940ae2
Step 7/11 : RUN mv /app/node_modules /node_modules
---> Running in 0f53a2cdd8e4
mv: cannot remove '/app/node_modules/.bin/mime': No such file or directory
mv: cannot remove '/app/node_modules/.bin/semver': No such file or directory
mv: cannot remove '/app/node_modules/accepts/HISTORY.md': No such file or directory
mv: cannot remove '/app/node_modules/accepts/LICENSE': No such file or directory
mv: cannot remove '/app/node_modules/accepts/README.md': No such file or directory
mv: cannot remove '/app/node_modules/accepts/index.js': No such file or directory
mv: cannot remove '/app/node_modules/accepts/package.json': No such file or directory
mv: cannot remove '/app/node_modules/after/.npmignore': No such file or directory
mv: cannot remove '/app/node_modules/after/.travis.yml': No such file or directory
mv: cannot remove '/app/node_modules/after/LICENCE': No such file or directory
mv: cannot remove '/app/node_modules/after/README.md': No such file or directory
当此容器无法运行时,端口 5000 将不会监听。
一个问题已经创建以解决这个问题。