7、Docker容器数据卷volumes-from
生活随笔
收集整理的這篇文章主要介紹了
7、Docker容器数据卷volumes-from
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
文章目錄
- 1、運(yùn)行dc01容器
- 2、運(yùn)行dc02容器
- 3、運(yùn)行dc03容器
- 4、回到dc01查看容器
- 5、當(dāng)刪除dc01容器后,其他容器內(nèi)容仍然存在
小實(shí)驗(yàn)?zāi)康?#xff0c;通過(guò)volumes-from實(shí)現(xiàn)多個(gè)容器文件共享,有繼承之意
1、運(yùn)行dc01容器
docker run -it --name dc01 chengwen/centos查看容器目錄,并進(jìn)入dataVolumeContainer2 新建文件 dc01_add.txt
[root@99ed34ced394 /]# ls -l total 24 lrwxrwxrwx. 1 root root 7 May 11 2019 bin -> usr/bin drwxr-xr-x. 2 root root 6 May 31 08:41 dataVolumeContainer1 drwxr-xr-x. 2 root root 6 May 31 08:41 dataVolumeContainer2 drwxr-xr-x. 5 root root 360 May 31 08:41 dev drwxr-xr-x. 1 root root 62 May 31 08:41 etc drwxr-xr-x. 2 root root 6 May 11 2019 home lrwxrwxrwx. 1 root root 7 May 11 2019 lib -> usr/lib lrwxrwxrwx. 1 root root 9 May 11 2019 lib64 -> usr/lib64 drwx------. 2 root root 6 Jan 13 21:48 lost+found drwxr-xr-x. 2 root root 6 May 11 2019 media drwxr-xr-x. 2 root root 6 May 11 2019 mnt drwxr-xr-x. 2 root root 6 May 11 2019 opt dr-xr-xr-x. 177 root root 0 May 31 08:41 proc dr-xr-x---. 2 root root 4096 Jan 13 21:49 root drwxr-xr-x. 1 root root 20 May 31 08:41 run lrwxrwxrwx. 1 root root 8 May 11 2019 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 May 11 2019 srv dr-xr-xr-x. 13 root root 0 May 30 01:01 sys drwxrwxrwt. 7 root root 4096 Jan 13 21:49 tmp drwxr-xr-x. 12 root root 4096 Jan 13 21:49 usr drwxr-xr-x. 20 root root 4096 Jan 13 21:49 var[root@99ed34ced394 /]# cd dataVolumeContainer2 [root@99ed34ced394 dataVolumeContainer2]# ls [root@99ed34ced394 dataVolumeContainer2]# touch dc01_add.txt2、運(yùn)行dc02容器
[root@localhost ~]# docker run -it --name dc02 --volumes-from dc01 chengwen/centos同樣的進(jìn)入容器目錄,進(jìn)入dataVolumeContainer2并新建文件 dc02_add.txt
[root@cd1f16c63ed6 /]# ls -l total 24 lrwxrwxrwx. 1 root root 7 May 11 2019 bin -> usr/bin drwxr-xr-x. 2 root root 6 May 31 08:41 dataVolumeContainer1 drwxr-xr-x. 2 root root 25 May 31 08:42 dataVolumeContainer2 drwxr-xr-x. 5 root root 360 May 31 08:46 dev drwxr-xr-x. 1 root root 62 May 31 08:46 etc drwxr-xr-x. 2 root root 6 May 11 2019 home lrwxrwxrwx. 1 root root 7 May 11 2019 lib -> usr/lib lrwxrwxrwx. 1 root root 9 May 11 2019 lib64 -> usr/lib64 drwx------. 2 root root 6 Jan 13 21:48 lost+found drwxr-xr-x. 2 root root 6 May 11 2019 media drwxr-xr-x. 2 root root 6 May 11 2019 mnt drwxr-xr-x. 2 root root 6 May 11 2019 opt dr-xr-xr-x. 178 root root 0 May 31 08:46 proc dr-xr-x---. 2 root root 4096 Jan 13 21:49 root drwxr-xr-x. 1 root root 20 May 31 08:46 run lrwxrwxrwx. 1 root root 8 May 11 2019 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 May 11 2019 srv dr-xr-xr-x. 13 root root 0 May 30 01:01 sys drwxrwxrwt. 7 root root 4096 Jan 13 21:49 tmp drwxr-xr-x. 12 root root 4096 Jan 13 21:49 usr drwxr-xr-x. 20 root root 4096 Jan 13 21:49 var [root@cd1f16c63ed6 /]# cd dataVolumeContainer2 [root@cd1f16c63ed6 dataVolumeContainer2]# ls dc01_add.txt [root@cd1f16c63ed6 dataVolumeContainer2]# touch dc02_add.txt3、運(yùn)行dc03容器
docker run -it --name dc03 --volumes-from dc01 chengwen/centos同樣的進(jìn)入容器目錄,進(jìn)入dataVolumeContainer2并新建文件 dc03_add.txt
cd dataVolumeContainer2 [root@0e19d8733ab1 dataVolumeContainer2]# ls dc01_add.txt dc02_add.txt [root@0e19d8733ab1 dataVolumeContainer2]# touch dc03_add.txt4、回到dc01查看容器
[root@localhost ~]# docker attach dc01 [root@99ed34ced394 /]# ls bin dataVolumeContainer2 etc lib lost+found mnt proc run srv tmp var dataVolumeContainer1 dev home lib64 media opt root sbin sys usr [root@99ed34ced394 /]# cd dataVolumeContainer2 [root@99ed34ced394 dataVolumeContainer2]# ls dc01_add.txt dc02_add.txt dc03_add.txtdocker attach dc01 進(jìn)入容器dc01
可以看到容器dc01里面有dc02、dc03新建的文件
dc02里面也有dc01和dc03里面的文件,
dc03里面也有dc01和dc02里面的文件,實(shí)現(xiàn)了文件共享
5、當(dāng)刪除dc01容器后,其他容器內(nèi)容仍然存在
總結(jié)
以上是生活随笔為你收集整理的7、Docker容器数据卷volumes-from的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 6、Dcoker 容器数据卷用Docke
- 下一篇: 1、MySQL 8.0.20最新版本在L