测试开发技术网站
博客
设计
设计
开发
Python
测试
unittest
运维
Linux基础应用
CI/CD
CI/CD
数据库
数据库
云计算
云计算
云原生
云原生
爬虫
爬虫
数据分析
数据分析
人工智能
人工智能
登录
注册
Docker----Docker数据共享与数据卷挂载
收藏本文
作者:redrose2100 类别: 日期:2022-05-03 13:50:08 阅读:871 次 消耗积分:0 分
![](https://redrose2100.oss-cn-hangzhou.aliyuncs.com/img/06c9f19c-9517-11ee-b9ec-0242ac110004.png) [TOC] # 一、使用docker run -v 具名数据卷挂载方式 (1)首先将本地 /opt/demo 目录删除 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# rm -rf /opt/demo/ [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# ``` (2)使用centos镜像,启动名为docker01的容器,并将docker中 /opt/demo 目录挂载到本地 /opt/demo目录 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# docker run -it --name docker01 -v /opt/demo:/opt/demo centos [root@6c84200b03e0 /]# ls /opt/demo/ [root@6c84200b03e0 /]# ``` (3)新打开一个终端,继续使用centos镜像,启动名为docker02的容器,此时注意使用 --volumes-from 指定docker02容器雨docker01容器共享数据卷 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker run --name docker02 -it --volumes-from docker01 centos [root@aeefb255149a /]# ls /opt/demo/ [root@aeefb255149a /]# ``` (4)同上继续启动一个docker03的容器,同样与docker01共享数据卷 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker run --name docker03 -it --volumes-from docker01 centos [root@b6b27b6b6d06 /]# ls /opt/demo/ [root@b6b27b6b6d06 /]# ``` (5)在宿主机 /opt/demo/目录下创建一个文件 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# touch test_docker.txt [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# ls test_docker.txt [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# pwd /opt/demo [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# ``` (6)此时到三个docker容器中查看,发现三个容器的 /opt/demo 目录下均有创建的test_docker.txt文件,即做到了数据共享与同步 ``` [root@6c84200b03e0 /]# ls /opt/demo/ test_docker.txt [root@6c84200b03e0 /]# ``` (7)此时将docker01停掉,发现docker02和docker03的/opt/demo目录下得文件仍然不会丢失 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b6b27b6b6d06 centos "/bin/bash" 18 minutes ago Up 18 minutes docker03 aeefb255149a centos "/bin/bash" 19 minutes ago Up 19 minutes docker02 91d5f6c93fa5 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql 1906e95db7ab nginx "/docker-entrypoint.…" 2 weeks ago Up 19 hours 0.0.0.0:80->80/tcp, :::80->80/tcp nginx [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# ``` 容器docker02中的数据依然存在 ``` [root@aeefb255149a /]# ls /opt/demo/ test_docker.txt [root@aeefb255149a /]# ``` # 二、使用docker run -v 匿名数据卷挂载方式 (1)首先将本地 /opt/demo 目录删除 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# rm -rf /opt/demo/ [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# ``` (2)使用centos镜像,启动名为docker01的容器,并将docker中 /opt/demo 目录匿名挂载到宿主机本地 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# docker run -it --name docker01 -v /opt/demo centos [root@4ff466c1d17b /]# ls /opt/demo/ [root@4ff466c1d17b /]# ``` (3)新打开一个终端,继续使用centos镜像,启动名为docker02的容器,此时注意使用 --volumes-from 指定docker02容器雨docker01容器共享数据卷 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker run --name docker02 -it --volumes-from docker01 centos [root@a36a479a87a1 /]# ls /opt/demo/ [root@a36a479a87a1 /]# ``` (4)同上继续启动一个docker03的容器,同样与docker01共享数据卷 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker run --name docker03 -it --volumes-from docker01 centos [root@f5cff0d857b2 /]# ls /opt/demo/ [root@f5cff0d857b2 /]# ``` (5)在宿主机 /opt/demo/目录下创建一个文件 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# touch test_docker.txt [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# ls test_docker.txt [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# pwd /opt/demo [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# ``` (6)此时到三个docker容器中查看,发现三个容器的 /opt/demo 目录下均有创建的test_docker.txt文件,即做到了数据共享与同步 ``` [root@6c84200b03e0 /]# ls /opt/demo/ test_docker.txt [root@6c84200b03e0 /]# ``` (7)此时将docker01停掉,发现docker02和docker03的/opt/demo目录下得文件仍然不会丢失 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b6b27b6b6d06 centos "/bin/bash" 18 minutes ago Up 18 minutes docker03 aeefb255149a centos "/bin/bash" 19 minutes ago Up 19 minutes docker02 91d5f6c93fa5 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql 1906e95db7ab nginx "/docker-entrypoint.…" 2 weeks ago Up 19 hours 0.0.0.0:80->80/tcp, :::80->80/tcp nginx [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# ``` 容器docker02中的数据依然存在 ``` [root@aeefb255149a /]# ls /opt/demo/ test_docker.txt [root@aeefb255149a /]# ``` (8)通过如下命令可以查询到匿名挂载其实也是挂载到宿主机的具体一个位置的 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f5cff0d857b2 centos "/bin/bash" About a minute ago Up About a minute docker03 a36a479a87a1 centos "/bin/bash" 3 minutes ago Up 3 minutes docker02 4ff466c1d17b centos "/bin/bash" 4 minutes ago Up 4 minutes docker01 91d5f6c93fa5 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql 1906e95db7ab nginx "/docker-entrypoint.…" 2 weeks ago Up 19 hours 0.0.0.0:80->80/tcp, :::80->80/tcp nginx [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# docker inspect 4ff466c1d17b [ { "Id": "4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f", "Created": "2021-10-27T09:34:32.465405207Z", "Path": "/bin/bash", "Args": [], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 11728, "ExitCode": 0, "Error": "", "StartedAt": "2021-10-27T09:34:34.305904504Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6", "ResolvConfPath": "/var/lib/docker/containers/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f/resolv.conf", "HostnamePath": "/var/lib/docker/containers/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f/hostname", "HostsPath": "/var/lib/docker/containers/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f/hosts", "LogPath": "/var/lib/docker/containers/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f-json.log", "Name": "/docker01", "RestartCount": 0, "Driver": "overlay2", "Platform": "linux", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": {}, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "CgroupnsMode": "host", "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", "ConsoleSize": [ 0, 0 ], "Isolation": "", "CpuShares": 0, "Memory": 0, "NanoCpus": 0, "CgroupParent": "", "BlkioWeight": 0, "BlkioWeightDevice": [], "BlkioDeviceReadBps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteIOps": null, "CpuPeriod": 0, "CpuQuota": 0, "CpuRealtimePeriod": 0, "CpuRealtimeRuntime": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": [], "DeviceCgroupRules": null, "DeviceRequests": null, "KernelMemory": 0, "KernelMemoryTCP": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": null, "OomKillDisable": false, "PidsLimit": null, "Ulimits": null, "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" ], "ReadonlyPaths": [ "/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger" ] }, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/b00f9966214f9a057d1732bd90a2bc19d8b1fedeed3e8ed3fb699b5bca317b3c-init/diff:/var/lib/docker/overlay2/44f13cfae31a605a465441c1e094b1d581783bf4f928fd70a67bbba3bfc836b2/diff", "MergedDir": "/var/lib/docker/overlay2/b00f9966214f9a057d1732bd90a2bc19d8b1fedeed3e8ed3fb699b5bca317b3c/merged", "UpperDir": "/var/lib/docker/overlay2/b00f9966214f9a057d1732bd90a2bc19d8b1fedeed3e8ed3fb699b5bca317b3c/diff", "WorkDir": "/var/lib/docker/overlay2/b00f9966214f9a057d1732bd90a2bc19d8b1fedeed3e8ed3fb699b5bca317b3c/work" }, "Name": "overlay2" }, "Mounts": [ { "Type": "volume", "Name": "4f97acbe3e7898dd26c93908c71e274140d1b8645d7e5310c65f5031751b62f0", ****"Source": "/var/lib/docker/volumes/4f97acbe3e7898dd26c93908c71e274140d1b8645d7e5310c65f5031751b62f0/_data", "Destination": "/opt/demo",**** "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], "Config": { "Hostname": "4ff466c1d17b", "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": { "/opt/demo": {} }, "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": "91e5156145cfaa67d84d2fe265b1b924887179468dab266830dfb3cfb59e7401", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/91e5156145cf", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "b8cd426f1e3a296bf96b6713a24c519452e313980a23878546add9f306f2f666", "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, "NetworkID": "9741ca08001e6aa41459744be801eafabaabd121c25c1ae93184d965f501b5ae", "EndpointID": "b8cd426f1e3a296bf96b6713a24c519452e313980a23878546add9f306f2f666", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.3", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:03", "DriverOpts": null } } } } ] [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# ``` 可以看到匿名挂载,其实是自动挂载到宿主机的某个位置,通过上述命令可以准确的查询到 ```bash ****"Source": "/var/lib/docker/volumes/4f97acbe3e7898dd26c93908c71e274140d1b8645d7e5310c65f5031751b62f0/_data", "Destination": "/opt/demo",**** ``` # 三、使用Dockerfile中Volume 匿名数据卷挂载方式 (1)编写内容如下的Dockerfile,保存文件名为Dockerfile ``` FROM centos MAINTAINER hitredrose@163.com VOLUME ["/opt/demo"] CMD /bin/bash ``` (2)使用Dockerfile编译一个docker镜像 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ home]# docker build -f Dockerfile -t redrose2100/centos:1.1 . Sending build context to Docker daemon 156.1MB Step 1/4 : FROM centos ---> 5d0da3dc9764 Step 2/4 : MAINTAINER hitredrose@163.com ---> Running in d4f0bf0ee314 Removing intermediate container d4f0bf0ee314 ---> e9fb5fb8c7a6 Step 3/4 : VOLUME ["/opt/demo"] ---> Running in d85c7ad69107 Removing intermediate container d85c7ad69107 ---> 9c2dba55a23d Step 4/4 : CMD /bin/bash ---> Running in e8cbd7c590ec Removing intermediate container e8cbd7c590ec ---> 2184c3aadaab Successfully built 2184c3aadaab Successfully tagged redrose2100/centos:1.1 [root@iZbp1flzt6x7pxmxfhmxeeZ home]# ``` (3)使用如下命令启动docker01 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ home]# docker run -it --name docker01 redrose2100/centos:1.1 [root@a09fd22cbc42 /]# ls /opt/demo/ [root@a09fd22cbc42 /]# ``` (4)启动docker02 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker run --name docker02 -it --volumes-from docker01 redrose2100/centos:1.1 [root@8db2290977fd /]# ls /opt/demo/ [root@8db2290977fd /]# ``` (5)启动docker03 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ ~]# docker run --name docker03 -it --volumes-from docker01 redrose2100/centos:1.1 [root@5a755b99c988 /]# ls /opt/demo/ [root@5a755b99c988 /]# ``` (6)在宿主机 /opt/demo/目录下创建一个文件 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# touch test_docker.txt [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# ls test_docker.txt [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# pwd /opt/demo [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# ``` (7)此时到三个docker容器中查看,发现三个容器的 /opt/demo 目录下均有创建的test_docker.txt文件,即做到了数据共享与同步 ``` [root@6c84200b03e0 /]# ls /opt/demo/ test_docker.txt [root@6c84200b03e0 /]# ``` (8)此时将docker01停掉,发现docker02和docker03的/opt/demo目录下得文件仍然不会丢失 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b6b27b6b6d06 centos "/bin/bash" 18 minutes ago Up 18 minutes docker03 aeefb255149a centos "/bin/bash" 19 minutes ago Up 19 minutes docker02 91d5f6c93fa5 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql 1906e95db7ab nginx "/docker-entrypoint.…" 2 weeks ago Up 19 hours 0.0.0.0:80->80/tcp, :::80->80/tcp nginx [root@iZbp1flzt6x7pxmxfhmxeeZ opt]# ``` 容器docker02中的数据依然存在 ``` [root@aeefb255149a /]# ls /opt/demo/ test_docker.txt [root@aeefb255149a /]# ``` (9)通过如下命令可以查询到匿名挂载其实也是挂载到宿主机的具体一个位置的 ``` [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f5cff0d857b2 centos "/bin/bash" About a minute ago Up About a minute docker03 a36a479a87a1 centos "/bin/bash" 3 minutes ago Up 3 minutes docker02 4ff466c1d17b centos "/bin/bash" 4 minutes ago Up 4 minutes docker01 91d5f6c93fa5 mysql:5.7 "docker-entrypoint.s…" 2 weeks ago Up 2 weeks 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql 1906e95db7ab nginx "/docker-entrypoint.…" 2 weeks ago Up 19 hours 0.0.0.0:80->80/tcp, :::80->80/tcp nginx [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# docker inspect 4ff466c1d17b [ { "Id": "4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f", "Created": "2021-10-27T09:34:32.465405207Z", "Path": "/bin/bash", "Args": [], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 11728, "ExitCode": 0, "Error": "", "StartedAt": "2021-10-27T09:34:34.305904504Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6", "ResolvConfPath": "/var/lib/docker/containers/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f/resolv.conf", "HostnamePath": "/var/lib/docker/containers/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f/hostname", "HostsPath": "/var/lib/docker/containers/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f/hosts", "LogPath": "/var/lib/docker/containers/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f/4ff466c1d17b0e8ac266f54181149ba163e08e7720974a813f0310ddb1773e0f-json.log", "Name": "/docker01", "RestartCount": 0, "Driver": "overlay2", "Platform": "linux", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": {}, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "CgroupnsMode": "host", "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", "ConsoleSize": [ 0, 0 ], "Isolation": "", "CpuShares": 0, "Memory": 0, "NanoCpus": 0, "CgroupParent": "", "BlkioWeight": 0, "BlkioWeightDevice": [], "BlkioDeviceReadBps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteIOps": null, "CpuPeriod": 0, "CpuQuota": 0, "CpuRealtimePeriod": 0, "CpuRealtimeRuntime": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": [], "DeviceCgroupRules": null, "DeviceRequests": null, "KernelMemory": 0, "KernelMemoryTCP": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": null, "OomKillDisable": false, "PidsLimit": null, "Ulimits": null, "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" ], "ReadonlyPaths": [ "/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger" ] }, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/b00f9966214f9a057d1732bd90a2bc19d8b1fedeed3e8ed3fb699b5bca317b3c-init/diff:/var/lib/docker/overlay2/44f13cfae31a605a465441c1e094b1d581783bf4f928fd70a67bbba3bfc836b2/diff", "MergedDir": "/var/lib/docker/overlay2/b00f9966214f9a057d1732bd90a2bc19d8b1fedeed3e8ed3fb699b5bca317b3c/merged", "UpperDir": "/var/lib/docker/overlay2/b00f9966214f9a057d1732bd90a2bc19d8b1fedeed3e8ed3fb699b5bca317b3c/diff", "WorkDir": "/var/lib/docker/overlay2/b00f9966214f9a057d1732bd90a2bc19d8b1fedeed3e8ed3fb699b5bca317b3c/work" }, "Name": "overlay2" }, "Mounts": [ { "Type": "volume", "Name": "4f97acbe3e7898dd26c93908c71e274140d1b8645d7e5310c65f5031751b62f0", ****"Source": "/var/lib/docker/volumes/4f97acbe3e7898dd26c93908c71e274140d1b8645d7e5310c65f5031751b62f0/_data", "Destination": "/opt/demo",**** "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], "Config": { "Hostname": "4ff466c1d17b", "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": { "/opt/demo": {} }, "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": "91e5156145cfaa67d84d2fe265b1b924887179468dab266830dfb3cfb59e7401", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/91e5156145cf", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "b8cd426f1e3a296bf96b6713a24c519452e313980a23878546add9f306f2f666", "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, "NetworkID": "9741ca08001e6aa41459744be801eafabaabd121c25c1ae93184d965f501b5ae", "EndpointID": "b8cd426f1e3a296bf96b6713a24c519452e313980a23878546add9f306f2f666", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.3", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:03", "DriverOpts": null } } } } ] [root@iZbp1flzt6x7pxmxfhmxeeZ demo]# ``` 可以看到匿名挂载,其实是自动挂载到宿主机的某个位置,通过上述命令可以准确的查询到 ```bash ****"Source": "/var/lib/docker/volumes/4f97acbe3e7898dd26c93908c71e274140d1b8645d7e5310c65f5031751b62f0/_data", "Destination": "/opt/demo",**** ```
始终坚持开源开放共享精神,同时感谢您的充电鼓励和支持!
版权所有,转载本站文章请注明出处:redrose2100, http://blog.redrose2100.com/article/63
上一篇: 没有了
下一篇:
Docker----Docker自定义网络
搜索
个人成就
出版书籍
《Pytest企业级应用实战》
测试开发技术全栈公众号
测试开发技术全栈公众号
DevOps技术交流微信群
加微信邀请进群
常用网站链接
开源软件洞察
云原生技术栈全景图
Python语言官方文档
Golang官方文档
Docker官方文档
Jenkins中文用户手册
Scrapy官方文档
VUE官方文档
Harbor官方文档
openQA官方文档
云原生开源社区
开源中国
Kubernetes中文文档
Markdown语法官方教程
Kubernetes中文社区
Kubersphere官方文档
BootStrap中文网站
JavaScript中文网
NumPy官方文档
Pandas官方文档
GitLink确实开源网站
数据库排名网站
编程语言排名网站
SEO综合查询网站
数学加减法练习自动生成网站
Kickstart Generator
文章分类
最新文章
最多阅读
特别推荐
×
Close
登录
注册
找回密码
登录邮箱:
登录密码:
图片验证码:
注册邮箱:
注册密码:
邮箱验证码:
发送邮件
注册邮箱:
新的密码:
邮箱验证码:
发送邮件