欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker(5)-Docker之间数据共享技术即数据卷容器

程序员文章站 2024-03-15 11:13:59
...

一、使用docker run -v 具名数据卷挂载方式

(1)首先将本地 /opt/demo 目录删除
[[email protected] opt]# rm -rf /opt/demo/
[[email protected] opt]#
(2)使用centos镜像,启动名为docker01的容器,并将docker中 /opt/demo 目录挂载到本地 /opt/demo目录
[[email protected] opt]# docker run -it --name docker01 -v /opt/demo:/opt/demo centos
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(3)新打开一个终端,继续使用centos镜像,启动名为docker02的容器,此时注意使用 --volumes-from 指定docker02容器雨docker01容器共享数据卷
[[email protected] ~]# docker run --name docker02 -it --volumes-from docker01 centos
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(4)同上继续启动一个docker03的容器,同样与docker01共享数据卷
[[email protected] ~]# docker run --name docker03 -it --volumes-from docker01 centos
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(5)在宿主机 /opt/demo/目录下创建一个文件
[[email protected] demo]# touch test_docker.txt
[[email protected] demo]# ls
test_docker.txt
[[email protected] demo]# pwd
/opt/demo
[[email protected] demo]#
(6)此时到三个docker容器中查看,发现三个容器的 /opt/demo 目录下均有创建的test_docker.txt文件,即做到了数据共享与同步
[[email protected] /]# ls /opt/demo/
test_docker.txt
[[email protected] /]#
(7)此时将docker01停掉,发现docker02和docker03的/opt/demo目录下得文件仍然不会丢失
[[email protected] 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
[[email protected] opt]#

容器docker02中的数据依然存在

[[email protected] /]# ls /opt/demo/
test_docker.txt
[[email protected] /]#

二、使用docker run -v 匿名数据卷挂载方式

(1)首先将本地 /opt/demo 目录删除
[[email protected] opt]# rm -rf /opt/demo/
[[email protected] opt]#
(2)使用centos镜像,启动名为docker01的容器,并将docker中 /opt/demo 目录匿名挂载到宿主机本地
[[email protected] opt]# docker run -it --name docker01 -v /opt/demo  centos
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(3)新打开一个终端,继续使用centos镜像,启动名为docker02的容器,此时注意使用 --volumes-from 指定docker02容器雨docker01容器共享数据卷
[[email protected] ~]# docker run --name docker02 -it --volumes-from docker01 centos
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(4)同上继续启动一个docker03的容器,同样与docker01共享数据卷
[[email protected] ~]# docker run --name docker03 -it --volumes-from docker01 centos
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(5)在宿主机 /opt/demo/目录下创建一个文件
[[email protected] demo]# touch test_docker.txt
[[email protected] demo]# ls
test_docker.txt
[[email protected] demo]# pwd
/opt/demo
[[email protected] demo]#
(6)此时到三个docker容器中查看,发现三个容器的 /opt/demo 目录下均有创建的test_docker.txt文件,即做到了数据共享与同步
[[email protected] /]# ls /opt/demo/
test_docker.txt
[[email protected] /]#
(7)此时将docker01停掉,发现docker02和docker03的/opt/demo目录下得文件仍然不会丢失
[[email protected] 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
[[email protected] opt]#

容器docker02中的数据依然存在

[[email protected] /]# ls /opt/demo/
test_docker.txt
[[email protected] /]#
(8)通过如下命令可以查询到匿名挂载其实也是挂载到宿主机的具体一个位置的
[[email protected] 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
[[email protected] 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
                }
            }
        }
    }
]
[[email protected] demo]#

可以看到匿名挂载,其实是自动挂载到宿主机的某个位置,通过上述命令可以准确的查询到
Docker(5)-Docker之间数据共享技术即数据卷容器

三、使用Dockerfile中Volume 匿名数据卷挂载方式

(1)编写内容如下的Dockerfile,保存文件名为Dockerfile
FROM centos

MAINTAINER [email protected]

VOLUME ["/opt/demo"]

CMD /bin/bash
(2)使用Dockerfile编译一个docker镜像
[[email protected] 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 [email protected]
 ---> 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
[[email protected] home]#
(3)使用如下命令启动docker01
[[email protected] home]# docker run -it  --name docker01 redrose2100/centos:1.1
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(4)启动docker02
[[email protected] ~]# docker run --name docker02 -it --volumes-from docker01 redrose2100/centos:1.1
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(5)启动docker03
[[email protected] ~]# docker run --name docker03 -it --volumes-from docker01 redrose2100/centos:1.1
[[email protected] /]# ls /opt/demo/
[[email protected] /]#
(6)在宿主机 /opt/demo/目录下创建一个文件
[[email protected] demo]# touch test_docker.txt
[[email protected] demo]# ls
test_docker.txt
[[email protected] demo]# pwd
/opt/demo
[[email protected] demo]#
(7)此时到三个docker容器中查看,发现三个容器的 /opt/demo 目录下均有创建的test_docker.txt文件,即做到了数据共享与同步
[[email protected] /]# ls /opt/demo/
test_docker.txt
[[email protected] /]#
(8)此时将docker01停掉,发现docker02和docker03的/opt/demo目录下得文件仍然不会丢失
[[email protected] 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
[[email protected] opt]#

容器docker02中的数据依然存在

[[email protected] /]# ls /opt/demo/
test_docker.txt
[[email protected] /]#
(9)通过如下命令可以查询到匿名挂载其实也是挂载到宿主机的具体一个位置的
[[email protected] 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
[[email protected] 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
                }
            }
        }
    }
]
[[email protected] demo]#

可以看到匿名挂载,其实是自动挂载到宿主机的某个位置,通过上述命令可以准确的查询到
Docker(5)-Docker之间数据共享技术即数据卷容器