一、什么是存储卷
二、为什么要用到数据卷
三、数据卷是怎么被管理的
四、存储卷种类
五、在容器中使用存储卷
1、只声明容器路径
[root@localhost docker]# docker run --name b2 -it -v /data busybox
/ # ls /
bin data dev etc home proc root sys tmp usr var [root@localhost ~]# docker inspect -f {{.Mounts}} b2
[{volume ef7928df9feaa0d01e5219f7a0a52c84aa902a9c91effdb7ff3fd79d152f9ef8 /var/lib/docker/volumes/ef7928df9feaa0d01e5219f7a0a52c84aa902a9c91effdb7ff3fd79d152f9ef8/_data /data local true }]
也可以通过docker inspect 容器名 查看到卷名称和宿主机上的卷名称
2、声明主机路径和容器路径
[root@localhost docker]# docker run --name b2 -it --rm -v /data/volumes/b2:/data busybox
/ # ls
bin data dev etc home proc root sys tmp usr var
通过docker inspect b2查看Mounts信息
六、共享存储卷(即joind container,相当于共享名称空间中的文件系统)
1、创建容器1
[root@localhost docker]# docker run --name b2 -it --rm -v /data/volumes/b2:/data busybox
/ # ifconfig
eth0 Link encap:Ethernet HWaddr ::0A:::
inet addr:10.0.0.5 Bcast:10.0.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (648.0 B) TX bytes: (0.0 B) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 B) TX bytes: (0.0 B)
2、创建容器2,并且共享容器1的网络空间和文件系统
[root@localhost ~]# docker run --name b3 -it --network container:b2 --volumes-from b2 busybox
/ # ifconfig
eth0 Link encap:Ethernet HWaddr ::0A:::
inet addr:10.0.0.5 Bcast:10.0.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (648.0 B) TX bytes: (0.0 B) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 B) TX bytes: (0.0 B) / # ls
bin data dev etc home proc root sys tmp usr var