命令方式挂载
#创建挂载的volume信息
docker volume create --driver local --opt type=nfs --opt o=addr=192.168.207.120,rw --opt device=:/data/magicdata nfsvolume
#查询创建volume
docker volume ls
#容器挂载目录,注意需要在电脑上安装NFS客户端
docker run -d -it --name testnfs --mount source=nfsvolume,target=/data registry.cn-hangzhou.aliyuncs.com/heliang230/centos:7.6 /bin/bash
#清除volume资源
docker volume prune -f
docker-compose.yml方式挂载
version: "3.2"
services:
[service-name]:
image: [docker-image]
ports:
- "[port]:[port]"
volumes:
- type: volume
source: [volume-name]
target: /nfs
volume:
nocopy: true
volumes:
[volume-name]:
driver_opts:
type: "nfs"
o: "addr=[ip-address],nolock,soft,rw"
device: ":[path-to-directory]"
网友评论