首页 > 其他分享 >容器数据卷

容器数据卷

时间:2024-05-28 21:26:07浏览次数:20  
标签:容器 txt proc home root docker null 数据

**由来**

Docker 是将应用和环境打包成一个镜像。 这样,数据就不应该保存在容器中,否则容器删除,数据就会丢失,有着非常大的风险。 为此,容器和主机之间需要有一个数据共享技术,使得在 Docker 容器中产生的数据能够同步到本地。 这就是数据卷技术。其本质上是一个目录挂载,将容器内的目录挂载到主机上。

**使用**

1.挂载

[root@localhost ~]# `docker run -it -v /home/roo/:/home centos /bin/bash`

[root@439732944dea /]# cd home/
[root@439732944dea home]# ls
[root@439732944dea home]# touch a.txt
[root@439732944dea home]# ls
a.txt
[root@439732944dea home]# touch b.txt
[root@439732944dea home]# touch c.txt
[root@439732944dea home]# ls         
a.txt  b.txt  bbb  c.txt

2.主机查看

[root@localhost ~]# cd /home/
[root@localhost home]# ls
roo
[root@localhost home]# cd roo/
[root@localhost roo]# ls
a.txt  b.txt  c.txt
[root@localhost roo]# touch bbb
[root@localhost roo]# ls
a.txt  bbb  b.txt  c.txt

3.查看挂载信息

[root@localhost roo]# docker inspect 439732944dea

查看代码
 [
    {
        "Id": "439732944dea832eb6c55d08966a87260b45260d6bf8fbeb59e81a5a851ceb65",
        "Created": "2024-05-28T12:54:50.427403411Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 15119,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-05-28T12:54:50.743374799Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "ResolvConfPath": "/var/lib/docker/containers/439732944dea832eb6c55d08966a87260b45260d6bf8fbeb59e81a5a851ceb65/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/439732944dea832eb6c55d08966a87260b45260d6bf8fbeb59e81a5a851ceb65/hostname",
        "HostsPath": "/var/lib/docker/containers/439732944dea832eb6c55d08966a87260b45260d6bf8fbeb59e81a5a851ceb65/hosts",
        "LogPath": "/var/lib/docker/containers/439732944dea832eb6c55d08966a87260b45260d6bf8fbeb59e81a5a851ceb65/439732944dea832eb6c55d08966a87260b45260d6bf8fbeb59e81a5a851ceb65-json.log",
        "Name": "/pensive_bartik",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/home/roo/:/home"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "bridge",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                41,
                102
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "private",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "PidsLimit": null,
            "Ulimits": [],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware",
                "/sys/devices/virtual/powercap"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/1055d2ae164ff6fdacc9432765a585e2274d4eb5eb9f25ea5709cbe8a69ba2ec-init/diff:/var/lib/docker/overlay2/5011e75a42f46fdc508b256c9d323103abcc258f08f1608f57e813a4fd47bfec/diff",
                "MergedDir": "/var/lib/docker/overlay2/1055d2ae164ff6fdacc9432765a585e2274d4eb5eb9f25ea5709cbe8a69ba2ec/merged",
                "UpperDir": "/var/lib/docker/overlay2/1055d2ae164ff6fdacc9432765a585e2274d4eb5eb9f25ea5709cbe8a69ba2ec/diff",
                "WorkDir": "/var/lib/docker/overlay2/1055d2ae164ff6fdacc9432765a585e2274d4eb5eb9f25ea5709cbe8a69ba2ec/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/home/roo",
                "Destination": "/home",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "439732944dea",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20210915",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "3789d1f9b1472ad5e63ae546afdcd5ba77211cda54910389775f72c5ac790f75",
            "SandboxKey": "/var/run/docker/netns/3789d1f9b147",
            "Ports": {},
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "c4a436e01d0099b66f1fbabf53c39e87db6885fc01f9a9b1bc0f3afc4a4a18cc",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "MacAddress": "02:42:ac:11:00:03",
                    "NetworkID": "e45fcd10035c41062d04781650d7ede49afc5a3671a9a52d7d52c13f43c8036e",
                    "EndpointID": "c4a436e01d0099b66f1fbabf53c39e87db6885fc01f9a9b1bc0f3afc4a4a18cc",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "DriverOpts": null,
                    "DNSNames": null
                }
            }
        }
    }
]

标签:容器,txt,proc,home,root,docker,null,数据
From: https://www.cnblogs.com/muxinq/p/18218923

相关文章

  • 容器组件Tabs如何自定义 tabBar-高亮切换
    1.TabBar如果放在底部的话,一般会显示图形和文字,甚至有特殊的图标,如果要实现此类效果,就需要自定义tabBarTabs(){TabContent(){//内容略}.tabBar(this.tabBarBuilder())}@BuildertabBarBuilder(){//自定义的Tabbar结构}2.自定义TabBa......
  • 数据结构初阶 栈
    一.栈的基本介绍1.基本概念栈是一种线性表是一种特殊的数据结构栈顶:进行数据插入和删除操作的一端另一端叫做栈底压栈:插入数据叫做压栈压栈的数据在栈顶出栈:栈的删除操作叫做出栈出栈操作也是在栈顶栈遵循一个原则叫做后进先出(比如说子弹的弹夹其实就是一种设......
  • linux恢复数据
    linux恢复数据在Linux系统中恢复数据,可以采取多种方法,具体取决于数据丢失的原因和文件系统的类型。以下是一些常见的数据恢复方法:使用Undelete工具:首先,你需要使用如yum或apt-get等命令安装Undelete工具。查找被删除的文件。例如,在CentOS系统中,你可以使用sudoundelete/......
  • 【python】中国五大城市PM2.5 数据分析(含数据集及完整代码)
    目录问题描述(数据集、项目代码已资源绑定)前瞻 数据预处理数据可视化北京上海广州成都沈阳总览对比图北京部分代码问题描述(数据集、项目代码已资源绑定,见文章开头) 数据集前瞻         随着工业化和城市化的迅速发展,全球多个城市都面临着空气污......
  • 在Linux中,如何进行数据恢复?
    在Linux中进行数据恢复是一个相对复杂的过程,它涉及到多个方面和不同的恢复方法。以下是详细的数据恢复步骤和注意事项:1.评估数据丢失情况确定数据丢失原因:硬件故障、软件问题、误删除等。检查文件系统状态:使用如fsck命令检查文件系统的完整性。确定要恢复的数据:明确需要恢复......
  • SQL历理 neirongxitong数据库结构
    /*SQLyog企业版-MySQLGUIv8.14MySQL-5.6.28:Database-neirongxitong**********************************************************************//*!40101SETNAMESutf8*/;/*!40101SETSQL_MODE=''*/;/*!40014SET@OLD_UNIQUE_CHECKS=@@UNI......
  • Docker容器中的时间不对
    由于docker里的容器的时间不对,且还是离线的dockerexec-uroot-it<container_id_or_name>date-s"2024-05-2819:10:20"尽然权限还是不够使用root进去以后还是没有权限后面查到好像是dockerrun的时候少了--privileged但是我现在又不想删了容器重新搞查了好多方法最......
  • PostgreSQL数据库实战:轻松修改字段名称
    哈喽,大家好,我是木头左!在本文中,将深入探讨PostgreSQL数据库中的一个强大功能,即如何轻松修改字段名称。无论你是一个新手开发者,还是一个经验丰富的DBA,这篇文章都将为你提供实用的技巧和建议。一、为什么需要修改字段名称?在开发过程中,经常会遇到需要修改表结构的情况,比如添加新......
  • 用python字典统计CSV数据
    1.用python字典统计CSV数据的步骤和代码示例为了使用Python字典来统计CSV数据,我们可以使用内置的csv模块来读取CSV文件,并使用字典来存储统计信息。以下是一个详细的步骤和完整的代码示例:1.1步骤(1)导入csv模块。(2)打开CSV文件并读取数据。(3)初始化一个空字典来存储统计信息。(4)遍......
  • 【代码之髓】研究编程语言的核心点——结构化编程、函数、异常、作用域、类型、容器、
    写在前面本文基于人民邮电出版社发行的西尾泰和先生所著《代码之髓》有一定读书笔记性质,算是精简版改写。目录写在前面如何深入高效地学习语言从比较中学习从历史中学习程序设计语言诞生史语法的诞生程序的流程控制if诞生以前whilefor函数为什么要有函数函数的返回......