Docker 学习6 Docker存储卷
一、什么是存储卷
二、为什么要用到数据卷
三、数据卷是怎么被管理的
四、存储卷种类
五、在容器中使用存储卷
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 02:42:0A:00:00:05 inet addr:10.0.0.5 Bcast:10.0.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:648 (648.0 B) TX bytes:0 (0.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (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 02:42:0A:00:00:05 inet addr:10.0.0.5 Bcast:10.0.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:648 (648.0 B) TX bytes:0 (0.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) / # ls bin data dev etc home proc root sys tmp usr var