Carlhxl 2019-09-05
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" } ]
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服务上
#在管理节点上 docker service create --mount type=volume,src=volume-nfs,dst=/data/source/,volume-driver=local --name skplatform --hostname skplatform --network sk-net skplatform:dev