Docker安装
1、 使用官方安装脚本自动安装
#curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
2、启动 Docker 服务
#systemctl start docker
3、确认docker 组件已经启动
# ps aux | grep docker
root 11568 0.1 3.0 661408 56004 ? Ssl 08:44 0:54 /usr/bin/dockerd -H fd:// --
containerd=/run/containerd/containerd.sock
NFS介绍
NFS是Network File System的缩写,即网络文件系统。它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录。
下载NFS镜像文件
1、从docker-hub拉取NFS镜像
#docker pull erichough/nfs-server
2、验证镜像是否下载成功
#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
erichough/nfs-server latest 52e16db3eced 21 months ago 15.8MB
创建共享目录
1、创建共享目录
#mkdir -p /home/ap/nas_b
2、加载NFS驱动模块
#modprobe nfs
#modprobe nfsd
启动NFS容器
启动NFS容器
#docker run
--privileged -d \
-v /home/ap/nas_a:/nas_a \
-e NFS_EXPORT_0='/nas_a *(rw,sync,no_root_squash,no_all_squash,no_subtree_check,nohide,crossmnt)' \
-p 2049:2049 -p 2049:2049/udp \
-p 111:111 -p 111:111/udp \
-p 32765:32765 -p 32765:32765/udp \
-p 32767:32767 -p 32767:32767/udp \
-it --name ai-nas-a \
erichough/nfs-server
查看容器状态
查看容器运行状态
#docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a846cec1820 erichough/nfs-server "/usr/local/bin/entr…" 25 minutes ago Up 25 minutes 0.0.0.0:111->111/tcp, 0.0.0.0:111->111/udp, :::111->111/tcp, :::111->111/udp, 0.0.0.0:2049->2049/tcp, 0.0.0.0:2049->2049/udp, :::2049->2049/tcp, :::2049->2049/udp, 0.0.0.0:32765->32765/tcp, 0.0.0.0:32765->32765/udp, :::32765->32765/tcp, :::32765->32765/udp, 0.0.0.0:32767->32767/tcp, 0.0.0.0:32767->32767/udp, :::32767->32767/tcp, :::32767->32767/udp ai-nas-a
宿主机挂载共享目录
宿主机充当客户端挂载容器共享的目录
#mount -v -t nfs -o ro,nfsvers=3,nolock,proto=udp,port=2049 192.168.234.128:/nas_a /home/ap/nas_a
mount.nfs: timeout set for Tue Nov 16 00:28:30 2021
mount.nfs: trying text-based options 'nfsvers=3,nolock,proto=udp,port=2049,addr=192.168.234.128'
mount.nfs: prog 100005, trying vers=3, prot=17
mount.nfs: trying 192.168.234.128 prog 100005 vers 3 prot UDP port 32767
验证是否挂载成功
验证过载状态
#showmount -a 192.168.234.128
All mount points on 192.168.234.128:
192.168.234.128:/nas_a
#df
Filesystem 1K-blocks Used Available Use% Mounted on
192.168.234.128:/nas_a 9118720 7818816 1299904 86% /home/ap/nas_a