zoukankan      html  css  js  c++  java
  • 狂神说Docker基础学习笔记07 容器数据卷

    狂神说-Docker基础-学习笔记-07 容器数据卷

    视频地址:https://www.bilibili.com/video/BV1og4y1q7M4?p=21

    什么是容器数据卷

    运行时数据都在容器中,如果容器被删除,那么数据将丢失,为了解决数据保存和复用的问题,出现了容器的数据卷,即使,容器被删除数据也能得到保存,不同容器间也可以共享数据。

    其实就是实现了容器数据到本地数据的同步,这就是卷数据,这就是目录的挂载,将容器内的目录挂载到宿主机上面

    使用数据卷

    方式一:直接使用命令来挂载:docker run -it -v 主机目录:容器目录

    具体操作
    C:\Users\z>docker run -it --name centosV01 -v D:\dockerVMdata\centosHome\test:/home/test centos /bin/bash
    [root@9c3b5c17dfb7 /]# ls
    bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    [root@9c3b5c17dfb7 /]# cd home
    [root@9c3b5c17dfb7 home]# ls
    test
    [root@9c3b5c17dfb7 home]# cd test
    [root@9c3b5c17dfb7 test]# cd ..
    [root@9c3b5c17dfb7 home]# cd ..
    [root@9c3b5c17dfb7 /]# cd usr
    [root@9c3b5c17dfb7 usr]# ls
    bin  games  include  lib  lib64  libexec  local  sbin  share  src  tmp
    [root@9c3b5c17dfb7 usr]# cd ..
    [root@9c3b5c17dfb7 /]# cp -r usr/* home/test
    
    cp: cannot create directory 'home/test/share/terminfo/a': File exists
    cp: cannot create directory 'home/test/share/terminfo/e': File exists
    
    ^C
    [root@9c3b5c17dfb7 /]# cd home/test
    [root@9c3b5c17dfb7 test]# ls -a
    .  ..  bin  games  include  lib  lib64  libexec  local  sbin  share
    [root@9c3b5c17dfb7 test]# ls
    bin  games  include  lib  lib64  libexec  local  sbin  share
    [root@9c3b5c17dfb7 test]#
    C:\Users\z>docker ps
    CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
    9c3b5c17dfb7   centos    "/bin/bash"   7 minutes ago   Up 7 minutes             centosV01
    
    C:\Users\z>docker inspect 9c3b5c17dfb7
    [
        {
            "Id": "9c3b5c17dfb754d5e20834e89fd6ae89d17ba65b15bcd7f6966e72435fb71f66",
            "Created": "2021-11-20T16:31:04.5139086Z",
            "Path": "/bin/bash",
            "Args": [],
            "State": {
            
                                #·············#
            
            },
            "Mounts": [
                {
                    "Type": "bind",
                    "Source": "D:\\dockerVMdata\\centosHome\\test",
                    "Destination": "/home/test",
                    "Mode": "",
                    "RW": true,
                    "Propagation": "rprivate"
                }
            ],
            "Config": {
            
                                #·············#
            
            }
        }
    ]
    

    查看本地的test目录:

    可以看到文件是同步过来了的

    那么是否能将主机的数据同步到容器呢?

    新建一个文件夹,

    我们到 容器中查看

    新建文件夹在centos中解码成为了代码,为了更直观体现效果又在宿主机数据卷中添加了HelloWorld文件夹

    结果如下

    到此 无论是容器内部数据同步到外部还是外部数据同步到内部,都是可以实现的。

    这一操作的意义就是可以支持通过docker来运行一些数据库的环境而不用安装在物理机上,减轻

    配置环境的复杂度和物理机的运行负载

    特性

    容器数据可以同步到宿主机

    宿主机数据可以同步到容器

    停止容器,在宿主机操作数据,再次开启容器时,操作的结果也能同步

    所以,无论是容器停止还是删除数据都不会丢失,还可以通过容器来操作本地数据也可反之

  • 相关阅读:
    MarkDowdPad 破解
    VimFaultException A specified parameter was not correct configSpec.guestId
    did not finish being created even after we waited 189 seconds or 61 attempts. And its status is downloading
    nsx-edge虚拟机抓包实践
    检查子网内存活的主机
    测试防火墙源端口
    vmware创建虚拟机不识别网卡
    ovs-qos配置
    ovs之组网实验
    openstack镜像制作
  • 原文地址:https://www.cnblogs.com/OwlInTheOaktree/p/15583247.html
Copyright © 2011-2022 走看看