目录
一、配置NFS服务
1.1 NFS服务端配置
yum install nfs-utils rpcbind -y
mkdir -p /data/nfs/docker
echo "/data/nfs *(rw,async,no_root_squash)">>/etc/exports
exportfs -r
systemctl start rpcbind nfs-server
systemctl enable rpcbind nfs-server
showmount -e localhost
1.2 NFS客户端
yum install -y nfs-utils rpcbind
二、docker volume使用NFS存储
2.1 创建docker volume 连接 10.20.1.9:/data/nfs(NFS服务端)
docker volume create --driver local \
--opt type=nfs \
--opt o=addr=10.20.1.9,rw \
--opt device=:/data/nfs \
nfs-volume
--opt o=addr=10.20.1.9 NFS服务器地址
--opt device=:/root/share 指向共享目录,也可以是共享目录下的子目录
2.2 查看docker volume
docker volume ls
docker volume inspect nfs-volume
-------------
[
{
"CreatedAt": "2020-06-18T14:14:08+08:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/nfs-volume/_data",
"Name": "nfs-volume",
"Options": {
"device": ":/data/nfs",
"o": "addr=10.20.1.9,rw",
"type": "nfs"
},
"Scope": "local"
}
]
2.3 容器使用nfs-volume
docker run -dit --name busybox7 -v volume-nfs:/nfs busybox
三、docker-compose 使用NFS存储
version: '3.2'
services:
django:
container_name: django
build: ./
restart: always
ports:
- 8000:8000
volumes:
- type: volume
source: example
target: /data/blog
volume:
nocopy: true
command: "uwsgi --ini /data/blog/uwsgi.ini"
volumes:
example:
driver_opts:
type: "nfs"
o: "addr=10.20.1.9,rw"
device: ":/data/nfs"
发表评论
共 0 条评论
暂无评论