docker外挂nfs存储
一、nfs安装
1、安装依赖
yum -y install nfs-utils rpcbind
2、设定目录
mkdir /nfs -p chmod 777 /nfs
3、创建 exports
vi /etc/exports
加入:
/nfs *(rw,insecure,sync,no_subtree_check,no_root_squash)
生效
exportfs -r # 生效 exportfs #查看
4、重启服务
systemctl restart rpcbind && systemctl enable rpcbind
systemctl restart nfs && systemctl enable nfs
5、检查 nfs 服务器
showmount -e 192.168.5.14
6、本地测试客户端
mount -t nfs 192.168.5.14:/nfs /nfs_share
二、docker挂载
version: '3' services: xbd-mysql: image: mysql:8.0.19 restart: always container_name: xbd-mysql volumes: - nfs:/var/lib/mysql ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: root privileged: true command: ['--lower_case_table_names=1', '--character-set-server=utf8', '--collation-server=utf8_general_ci'] volumes: nfs: driver_opts: type: "nfs" o: "addr=192.168.5.14,nolock,soft,rw" device: ":/nfs/mysql"
测试:
也可以通过docker的方式创建volume
docker volume create nfs_name -d local -o type=nfs -o o=addr=192.168.5.14,nolock,soft,rw -o device=:/nfs/mysql