Create Docker Swarm v1.12.3 Service and Install NFS Volume

I cannot get the NFS volume mounted for Docker Swarm, and the lack of proper official documentation regarding the --mount syntax ( https://docs.docker.com/engine/reference/commandline/service_create/ ) does not help.

I basically tried this command line to create a simple nginx service with the / kkk directory installed on the NFS volume:

docker service create --mount type = volume, src = vol_name, volume-driver = local, dst = / kkk, volume-opt = type = nfs, volume-opt = device = 192.168.1.1:/your/nfs/path - -name test nginx

The command line is accepted and the service is assigned by Swarm, but the container never reaches the running state, and swarm tries to start a new instance every few seconds. I installed a daemon for debugging, but no errors regarding the volume displayed ...

What is the correct syntax for creating a service with an NFS volume?

Thank you so much

+4
source share
1 answer

I found an article here that shows how to mount the nfs share (and this works for me): http://collabnix.com/docker-1-12-swarm-mode-persistent-storage-using-nfs/

sudo docker service create \
--mount type=volume,volume-opt=o=addr=192.168.x.x,volume-opt=device=:/data/nfs,volume-opt=type=nfs,source=vol_collab,target=/mount \
--replicas 3 --name testnfs \
alpine /bin/sh -c "while true; do echo 'OK'; sleep 2; done"

Update:
If you want to use it with docker-compose, you can do the following:

version: '3'

services:

  alpine:
    image: alpine
    volumes:
      - vol_collab:/mount
    deploy:
      mode: replicated
      replicas: 2
    command: /bin/sh -c "while true; do echo 'OK'; sleep 2; done"


volumes:
  vol_collab:
    driver: local
    driver_opts:
      type: nfs
      o: addr=192.168.xx.xx
      device: ":/data/nfs"

and then run it with

docker stack deploy -c docker-compose.yml test
0
source

Source: https://habr.com/ru/post/1660473/


All Articles