日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

7、Docker容器数据卷volumes-from

發布時間:2025/3/19 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 7、Docker容器数据卷volumes-from 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

      • 1、運行dc01容器
      • 2、運行dc02容器
      • 3、運行dc03容器
      • 4、回到dc01查看容器
      • 5、當刪除dc01容器后,其他容器內容仍然存在

小實驗目的,通過volumes-from實現多個容器文件共享,有繼承之意

1、運行dc01容器

docker run -it --name dc01 chengwen/centos

查看容器目錄,并進入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.txt

2、運行dc02容器

[root@localhost ~]# docker run -it --name dc02 --volumes-from dc01 chengwen/centos

同樣的進入容器目錄,進入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.txt

3、運行dc03容器

docker run -it --name dc03 --volumes-from dc01 chengwen/centos

同樣的進入容器目錄,進入dataVolumeContainer2并新建文件 dc03_add.txt

cd dataVolumeContainer2 [root@0e19d8733ab1 dataVolumeContainer2]# ls dc01_add.txt dc02_add.txt [root@0e19d8733ab1 dataVolumeContainer2]# touch dc03_add.txt

4、回到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.txt

docker attach dc01 進入容器dc01

可以看到容器dc01里面有dc02、dc03新建的文件
dc02里面也有dc01和dc03里面的文件,
dc03里面也有dc01和dc02里面的文件,實現了文件共享

5、當刪除dc01容器后,其他容器內容仍然存在

總結

以上是生活随笔為你收集整理的7、Docker容器数据卷volumes-from的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。