Swarm集群使用共享volume

Swarm集群使用共享volume

  • NFS服务端,配置nfs共享
yum install nfs-utils rpcbind -y
mkdir -p /data/nfs/
echo "/data/nfs *(rw,no_root_squash,sync)" >> /etc/exports
exportfs -r
systemctl start rpcbind nfs-server
systemctl enable rpcbind nfs-server
showmount -e localhost

 #创建nfs docker共享volume

[root@localhost ~]# docker volume create --driver local --opt o=addr=192.168.18.17,rw --opt device=:/data/nfs volume-nfs
volume-nfs
[root@localhost ~]# docker volume ls
DRIVER              VOLUME NAME
local               volume-nfs
[root@localhost ~]# docker volume inspect volume-nfs
[
    {
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/volume-nfs/_data",
        "Name": "volume-nfs",
        "Options": {
            "device": ":/data/nfs",
            "o": "addr=192.168.18.17,rw"
        },
        "Scope": "local"
    }
]


  • nfs客户端
yum install -y nfs-utils rpcbind

 #挂载nfs盘到相应的目录

mount -t nfs 192.168.18.17:/data/nfs/ /data/nfs



 #创建volume 连接 192.168.18.17:/data/nfs
docker volume create --driver local \
  --opt type=nfs \
  --opt o=addr=192.168.18.17,rw \
  --opt device=:/data/nfs \
  volume-nfs

 #查看
docker volume ls
docker volume inspect volume-nfs

 #容器使用volume-nfs
docker run -dit --name busybox7 -v volume-nfs:/nfs busybox
 #查看
docker inspect -f {{.Mounts}} busybox7
df -h |grep /data/nfs
 #volume目录/var/lib/docker/volumes/volume-nfs/_data自动挂载到了nfs服务上

Swarm集群如果想要挂载nfs volume

 #在管理节点上
docker service create --mount type=volume,src=volume-nfs,dst=/data/source/,volume-driver=local --name skplatform --hostname skplatform --network sk-net skplatform:dev


#type=bind
docker service create \
  --name my-service \
  --mount type=bind,source=/path/on/host,destination=/path/in/container \
  nginx:alpine

    原文作者:大爷来玩呀你懂得
    原文地址: https://segmentfault.com/a/1190000020211259
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞