Docker Swarm and NFS volumes (starting container failed: error while mounting; volume failed to mount local volume)

Hello everyone! I want to create a Swarm cluster with three nodes and one shared volume (in windows 10). I use docker-machine for it:

docker-machine create -d virtualbox swarm1-mgr1
docker-machine create -d virtualbox swarm1-wrk1
docker-machine create -d virtualbox swarm1-wrk2

Next I initialize a manager node:

docker-machine ssh swarm1-mgr1 docker swarm init

And add workers:

docker-machine ssh swarm1-wrk1 docker swarm join --token ...
docker-machine ssh swarm1-wrk2 docker swarm join --token ...

Next I configurate my console to work with the manager node:

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

Then I created a register:

docker service create --name registry --publish 5006:5000 registry:2
docker-compose build
docker push localhost:5006/web

And finally I am trying to deploy my app:

docker stack deploy -c docker-compose.yml stack_1
docker service ps stack_1_web --no-trunc

But getting the next error messages:

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"

I don’t understand why Swarm does not see my volume. Any help will be appreciated. My end goal is deploy stack on three nodes with one shared volume.


Here is my 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

And 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)
1 Like