zoukankan      html  css  js  c++  java
  • docker 存储

    [root@docker01 ~]# docker run --name b1 -v /data -it busybox
    / # ls
    bin   data  dev   etc   home  proc  root  sys   tmp   usr   var
    / # ls /data/
    [root@docker01 ~]# docker inspect b1

    "Mounts": [
    {
    "Type": "volume",
    "Name": "8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05",
    "Source": "/var/lib/docker/volumes/8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05/_data",  ###宿主机卷目录
    "Destination": "/data",   ###容器卷目录
    "Driver": "local",
    "Mode": "",
    "RW": true,
    "Propagation": ""
    }
    ],

    "Volumes": {
                    "/data": {}
                },
    我们在宿主机的目录/var/lib/docker/volumes/8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05/_data创建一个文件:
    
    [root@docker01 ~]# cd /var/lib/docker/volumes/8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05/_data
    [root@docker01 _data]# pwd
    /var/lib/docker/volumes/8e29cf6fb31d3e3331e6bea06e299e2209cc5ecafcecce3314854ae91907ae05/_data
    [root@docker01 _data]# echo "hello container" >> test.html
    [root@docker01 _data]# ll
    total 4
    -rw-r--r-- 1 root root 16 Mar 28 04:23 test.html

    [root@docker01 ~]# docker run --name b1 -v /data -it busybox
    / # ls
    bin data dev etc home proc root sys tmp usr var
    / # ls /data/
    / # ls /data/
    test.html
    / # cat /data/test.html     ####此时容器上也有此文件
    hello container

    ####另外一种方式

    [root@docker01 ~]# docker run --name b1 --rm -v /data/volumes/b1:/data -it busybox
    / # 



    [root@docker01 ~]# docker inspect b1

    "Mounts": [
    {
    "Type": "bind",
    "Source": "/data/volumes/b1",
    "Destination": "/data",
    "Mode": "",
    "RW": true,
    "Propagation": "rprivate"
    }
    ],

    ######inspect 格式输出#####

    [root@docker01 ~]# docker inspect -f {{.NetworkSettings.Networks.bridge.Gateway}} b1
    172.17.0.1
    [root@docker01 ~]# docker inspect -f {{.NetworkSettings.Networks.bridge.MacAddress}} b1
    02:42:ac:11:00:02
    [root@docker01 ~]# 

    ######两个容器可共享一个存储卷#######

  • 相关阅读:
    C++ 的查漏补缺
    Model元数据解析
    Controller
    路由
    win8系统 Reflect 破解
    MVC运行原理
    源代码Log
    linq 分类
    EF 实体关系
    第二十六章 计算限制的异步操作
  • 原文地址:https://www.cnblogs.com/shanhua-fu/p/10621190.html
Copyright © 2011-2022 走看看