zoukankan      html  css  js  c++  java
  • docker 6:容器之间共享磁盘

    创建三个容器,然后共享磁盘,实现文件在三个容器之间传递同步修改。

    创建容器docker01,然后创建docker02和docker03继承docker01,即可实现文件的共享。

    [root@localhost ~]# docker images 
    REPOSITORY            TAG       IMAGE ID       CREATED        SIZE
    volume1/centos        latest    04b2be41fc6c   3 hours ago    209MB
    1. 创建并运行docker01:
    [root@localhost ~]# docker run -it --name docker01 volume1/centos
    [root@cc5648abda23 /]# ls -l
    total 0
    lrwxrwxrwx.   1 root root   7 Nov  3 15:22 bin -> usr/bin
    drwxr-xr-x.   2 root root   6 Apr  1 10:08 dataVolume1
    drwxr-xr-x.   2 root root   6 Apr  1 10:08 dataVolume2
    
      进入共享目录,创建1.txt [root@cc5648abda23 /]# cd /dataVolume1 [root@cc5648abda23 dataVolume1]# touch 1.txt [root@cc5648abda23 dataVolume1]# ls 1.txt [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cc5648abda23 volume1/centos "/bin/sh -c /bin/bash" 22 seconds ago Up 19 seconds docker01
    2.创建并运行docker02:
    [root@localhost ~]# docker run -it --name docker02 --volumes-from docker01 volume1/centos [root@d3029b48260e /]# ls -l total 0 lrwxrwxrwx. 1 root root 7 Nov 3 15:22 bin -> usr/bin drwxr-xr-x. 2 root root 19 Apr 1 10:09 dataVolume1 drwxr-xr-x. 2 root root 6 Apr 1 10:08 dataVolume2
      可以看到1.txt,创建2.txt [root@d3029b48260e /]# cd dataVolume1 [root@d3029b48260e dataVolume1]# ls -l total 0 -rw-r--r--. 1 root root 0 Apr 1 10:09 1.txt [root@d3029b48260e dataVolume1]# touch 2.txt [root@d3029b48260e dataVolume1]# ls -l total 0 -rw-r--r--. 1 root root 0 Apr 1 10:09 1.txt -rw-r--r--. 1 root root 0 Apr 1 10:11 2.txt
    3.创建并运行docker03: [root@localhost ~]# docker run -it --name docker03 --volumes-from docker01 volume1/centos [root@70c8a7164cda /]# ls -l total 0 lrwxrwxrwx. 1 root root 7 Nov 3 15:22 bin -> usr/bin drwxr-xr-x. 2 root root 32 Apr 1 10:11 dataVolume1 drwxr-xr-x. 2 root root 6 Apr 1 10:08 dataVolume2
      可以看到1.txt和2.txt,创建3.txt [root@70c8a7164cda /]# cd dataVolume1 [root@70c8a7164cda dataVolume1]# ls -l total 0 -rw-r--r--. 1 root root 0 Apr 1 10:09 1.txt -rw-r--r--. 1 root root 0 Apr 1 10:11 2.txt [root@70c8a7164cda dataVolume1]# touch 3.txt [root@70c8a7164cda dataVolume1]# ls -l total 0 -rw-r--r--. 1 root root 0 Apr 1 10:09 1.txt -rw-r--r--. 1 root root 0 Apr 1 10:11 2.txt -rw-r--r--. 1 root root 0 Apr 1 10:12 3.txt [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 70c8a7164cda volume1/centos "/bin/sh -c /bin/bash" 40 seconds ago Up 38 seconds docker03 d3029b48260e volume1/centos "/bin/sh -c /bin/bash" About a minute ago Up About a minute docker02 cc5648abda23 volume1/centos "/bin/sh -c /bin/bash" 3 minutes ago Up 3 minutes docker01








    其实这个时候我们去看三个容器的挂载情况,会发现他们的挂载是一样的,都是对应的宿主机的相同文件夹:

    [root@localhost ~]# docker inspect d3029b48260e "Mounts": [ { "Type": "volume", "Name": "3d78455dc61c42b02ed985c140fa5df799b722db481535c33a7af20c9ef777f4", "Source": "/var/lib/docker/volumes/3d78455dc61c42b02ed985c140fa5df799b722db481535c33a7af20c9ef777f4/_data", "Destination": "/dataVolume1", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" }, { "Type": "volume", "Name": "7d63ce25e13f6d382ac748acd1fcdeab7af505dc98ce95e54e4ab4e87a4c83d9", "Source": "/var/lib/docker/volumes/7d63ce25e13f6d382ac748acd1fcdeab7af505dc98ce95e54e4ab4e87a4c83d9/_data", "Destination": "/dataVolume2", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], [root@localhost ~]# docker inspect 70c8a7164cda Mounts "Mounts": [ { "Type": "volume", "Name": "3d78455dc61c42b02ed985c140fa5df799b722db481535c33a7af20c9ef777f4", "Source": "/var/lib/docker/volumes/3d78455dc61c42b02ed985c140fa5df799b722db481535c33a7af20c9ef777f4/_data", "Destination": "/dataVolume1", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" }, { "Type": "volume", "Name": "7d63ce25e13f6d382ac748acd1fcdeab7af505dc98ce95e54e4ab4e87a4c83d9", "Source": "/var/lib/docker/volumes/7d63ce25e13f6d382ac748acd1fcdeab7af505dc98ce95e54e4ab4e87a4c83d9/_data", "Destination": "/dataVolume2", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], [root@localhost ~]# docker inspect cc5648abda23 "Mounts": [ { "Type": "volume", "Name": "3d78455dc61c42b02ed985c140fa5df799b722db481535c33a7af20c9ef777f4", "Source": "/var/lib/docker/volumes/3d78455dc61c42b02ed985c140fa5df799b722db481535c33a7af20c9ef777f4/_data", "Destination": "/dataVolume1", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" }, { "Type": "volume", "Name": "7d63ce25e13f6d382ac748acd1fcdeab7af505dc98ce95e54e4ab4e87a4c83d9", "Source": "/var/lib/docker/volumes/7d63ce25e13f6d382ac748acd1fcdeab7af505dc98ce95e54e4ab4e87a4c83d9/_data", "Destination": "/dataVolume2", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ],

      

  • 相关阅读:
    ImageLightbox.js – 响应式的图片 Lightbox 插件
    精美素材:10套最新出炉的免费扁平图标下载
    盘点2013年那些最优秀的网页设计作品【系列三】
    12个带给你惊喜用户体验的手机界面设计
    一款效果精致的 jQuery 多层滑出菜单插件
    创意无限:20幅惊人的霓虹灯摄影照片欣赏
    『设计前沿』14款精致的国外 iOS7 图标设计示例
    2013年值得我们学习的网页设计作品【系列二】
    Summernote – 基于 Bootstrap 的文本编辑器
    『摄影欣赏』2013年微软必应搜索十大首页美图
  • 原文地址:https://www.cnblogs.com/tortoise512/p/14607685.html
Copyright © 2011-2022 走看看