我想创建一个包含三个节点和一个共享卷的 Swarm 集群(在 Windows 10 中)。我使用docker-machine:
docker-machine create -d virtualbox swarm1-mgr1
docker-machine create -d virtualbox swarm1-wrk1
docker-machine create -d virtualbox swarm1-wrk2
接下来我初始化一个管理节点:
docker-machine ssh swarm1-mgr1 docker swarm init
并添加工作人员:
docker-machine ssh swarm1-wrk1 docker swarm join --token ...
docker-machine ssh swarm1-wrk2 docker swarm join --token ...
接下来,我将控制台配置为与管理器节点一起使用:
docker-machine ssh swarm1-mgr1 "docker node ls"
docker-machine env swarm-mgr1
& "C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe" env swarm-mgr1 | Invoke-Expression
然后我创建了一个寄存器:
docker service create --name registry --publish 5006:5000 registry:2
docker-compose build
docker push localhost:5006/web
最后我正在尝试部署我的应用程序:
docker stack deploy -c docker-compose.yml stack_1
docker service ps stack_1_web --no-trunc
但收到下一条错误消息:
hinsjnux3nlufwav41shxnc9e \_ stack_1_web.1 localhost:5006/web:latest@sha256:b3a70a88bf6effd889dc6c27eb98f0011ea8b937a173841d76242c8c7a5a8756 swarm1-wrk2 Shutdown Failed 2 seconds ago "starting container failed: error while mounting volume '/mnt/sda1/var/lib/docker/volumes/stack_1_compose_flask_1/_data': failed to mount local volume: mount F:/desktop/test/compose_flask_1:/mnt/sda1/var/lib/docker/volumes/stack_1_compose_flask_1/_data, flags: 0x1000: no such file or directory"
f6mldjr9lumx22tn573hsxfv9 \_ stack_1_web.1 localhost:5006/web:latest@sha256:b3a70a88bf6effd889dc6c27eb98f0011ea8b937a173841d76242c8c7a5a8756 swarm1-wrk1 Shutdown Failed 7 seconds ago "starting container failed: error while mounting volume '/mnt/sda1/var/lib/docker/volumes/stack_1_compose_flask_1/_data': failed to mount local volume: mount F:/desktop/test/compose_flask_1:/mnt/sda1/var/lib/docker/volumes/stack_1_compose_flask_1/_data, flags: 0x1000: no such file or directory"
s5k6e06iv4xw1e20we883d9m4 \_ stack_1_web.1 localhost:5006/web:latest@sha256:b3a70a88bf6effd889dc6c27eb98f0011ea8b937a173841d76242c8c7a5a8756 swarm1-mgr1 Shutdown Failed 12 seconds ago "starting container failed: error while mounting volume '/mnt/sda1/var/lib/docker/volumes/stack_1_compose_flask_1/_data': failed to mount local volume: mount F:/desktop/test/compose_flask_1:/mnt/sda1/var/lib/docker/volumes/stack_1_compose_flask_1/_data, flags: 0x1000: no such file or directory"
y9ahpolvlhnqw2o6clijl5tm6 \_ stack_1_web.1 localhost:5006/web:latest@sha256:b3a70a88bf6effd889dc6c27eb98f0011ea8b937a173841d76242c8c7a5a8756 swarm1-mgr1 Shutdown Failed 17 seconds ago "starting container failed: error while mounting volume '/mnt/sda1/var/lib/docker/volumes/stack_1_compose_flask_1/_data': failed to mount local volume: mount F:/desktop/test/compose_flask_1:/mnt/sda1/var/lib/docker/volumes/stack_1_compose_flask_1/_data, flags: 0x1000: no such file or directory"
我不明白为什么 Swarm 看不到我的音量。任何帮助将不胜感激。我的最终目标是在具有一个共享卷的三个节点上部署堆栈。
这是我的docker-compose.yml:
version: '3.3'
services:
web:
image: localhost:5006/web:latest
build:
context: .
dockerfile: Dockerfile
ports:
- "5000:5000"
depends_on:
- redis
deploy:
replicas: 1
networks:
- webnet
volumes:
- compose_flask_1:/compose_flask_1
redis:
image: redis
networks:
- webnet
deploy:
placement:
constraints:
- 'node.role==manager'
visualizersvc:
image: dockersamples/visualizer
depends_on:
- redis
deploy:
placement:
constraints:
- 'node.role==manager'
ports:
- '5001'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
networks:
- webnet
networks:
webnet:
driver: overlay
attachable: true
volumes:
compose_flask_1:
driver: local
driver_opts:
type: nfs
o: nfsvers=4,addr=localhost,rw
device: ":F:/desktop/test/compose_flask_1"
Dockerfile:
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python ./app.py
requirements.txt:
flask
redis
和app.py:
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
def hello():
redis.incr('hits')
return 'Flask demo 1 has been viewed %s time(s).' % redis.get('hits')
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
UPD:我尝试在 Lunix VM 中做同样的事情,但我遇到了同样的错误