安装nfs-utils
yum -y install nfs-utils
mkdir nfs-share-dir
chown -R nfsnobody.nfsnobody nfs-share-dir
vim /etc/exports
nfs-share-dir 192.168.1.0/24(rw)
systemctl enable nfs
systemctl start nfs
创建volume
docker volume create --driver local --opt type=nfs --opt -o=addr=192.168.1.1,rw --opt device=:/nfs-share-dir --name volume-name
docker swarm 需要在每个节点上安装nfs-utils和创建volume
使用volume
docker swarm
docker service create --replicas 2 --mount src=volume-name,target=/container-dir image-name