Docker inspect 查询数据集Volume无效解决方法

在使用

docker inspect --format "{{Volumes}}" 4d91f6c96a0e
命令的时候查询Volume出现
Template parsing error: template: :1: function "Volumes" not defined

错误。主要原因应该是版本不正确的问题。然后我又用

docker inspect redis-master

查看所有信息如下

[
    {
        "Id": "4d91f6c96a0eef6c5f0dea9731bc4e0b8da3cc00cdff0676869cb7f3fd3c210a",
        "Created": "2018-05-19T00:20:21.273722278Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "/bin/bash"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 9644,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2018-05-19T00:20:22.046490978Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:bfcb1f6df2db8a62694aaa732a3133799db59c6fec58bfeda84e34299e7270a8",
        "ResolvConfPath": "/var/docker/containers/4d91f6c96a0eef6c5f0dea9731bc4e0b8da3cc00cdff0676869cb7f3fd3c210a/resolv.conf",
        "HostnamePath": "/var/docker/containers/4d91f6c96a0eef6c5f0dea9731bc4e0b8da3cc00cdff0676869cb7f3fd3c210a/hostname",
        "HostsPath": "/var/docker/containers/4d91f6c96a0eef6c5f0dea9731bc4e0b8da3cc00cdff0676869cb7f3fd3c210a/hosts",
        "LogPath": "/var/docker/containers/4d91f6c96a0eef6c5f0dea9731bc4e0b8da3cc00cdff0676869cb7f3fd3c210a/4d91f6c96a0eef6c5f0dea9731bc4e0b8da3cc00cdff0676869cb7f3fd3c210a-json.log",
        "Name": "/redis-master",
        "RestartCount": 0,
        "Driver": "overlay2",
        "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,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "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": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "overlay2",
            "Data": {
                "LowerDir": "/var/docker/overlay2/37a349f76825c61fbf0253b589f183733f1c765cd22404bdb2d5ce123920b655-init/diff:/var/docker/overlay2/e035b8c616e2ccf80818ba773523c2b2cbd061c89d6a7139815adacb5f3db2fb/diff:/var/docker/overlay2/2f18095a64b90fc673c8554c0afcd661c696ba7f378de1ddabb97ff1e657e82e/diff:/var/docker/overlay2/53a2ec22cf20794ed85bf6df9133a7ec1a1545a0a4e2aa09ff7145faf18ce7fa/diff:/var/docker/overlay2/4ba3b406a2e6aa927a89ea48ad44ef934acec7c5cc33cb2567a45310749ce115/diff:/var/docker/overlay2/22f1b4644e5bec8b634fea1d01bc70c2911f4b06476bb3286dd45628038e5254/diff:/var/docker/overlay2/48cf99ddc9370c1a0b0044eaf24b6180d8393519ae717435fab6da63cb42fa38/diff",
                "MergedDir": "/var/docker/overlay2/37a349f76825c61fbf0253b589f183733f1c765cd22404bdb2d5ce123920b655/merged",
                "UpperDir": "/var/docker/overlay2/37a349f76825c61fbf0253b589f183733f1c765cd22404bdb2d5ce123920b655/diff",
                "WorkDir": "/var/docker/overlay2/37a349f76825c61fbf0253b589f183733f1c765cd22404bdb2d5ce123920b655/work"
            }
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "b5f103eb4af4d341bec0815f646ae22ea039b47180bbdc64e3e874c96919c25a",
                "Source": "/var/docker/volumes/b5f103eb4af4d341bec0815f646ae22ea039b47180bbdc64e3e874c96919c25a/_data",
                "Destination": "/data",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "4d91f6c96a0e",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "6379/tcp": {}
            },
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.10",
                "REDIS_VERSION=4.0.9",
                "REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-4.0.9.tar.gz",
                "REDIS_DOWNLOAD_SHA=df4f73bc318e2f9ffb2d169a922dec57ec7c73dd07bccf875695dbeecd5ec510"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "redis",
            "Volumes": {
                "/data": {}
            },
            "WorkingDir": "/data",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "e522c0eb1166b1b39ea6c3ce71699758c5adc65dcb524217838254a90dc30441",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "6379/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/e522c0eb1166",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "0249f28241c9ad9b662fb7cbbd214b5dcd49f108c0833c0577cdc0e87cd3b3ea",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "7e9e8448f83ff83bc0cb0262aae8b60b1691679f7699752023b3b031aa8686cc",
                    "EndpointID": "0249f28241c9ad9b662fb7cbbd214b5dcd49f108c0833c0577cdc0e87cd3b3ea",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02"
                }
            }
        }
    }
]

发现在config里面的volume结果是

"/data": {}

说明没有得到结果

然后通过查询得到现在版本要得到数据集需要

sudo docker inspect redis-master | grep Mounts -A -20

命令 最后得到结果如下

 "Mounts": [
            {
                "Type": "volume",
                "Name": "b5f103eb4af4d341bec0815f646ae22ea039b47180bbdc64e3e874c96919c25a",
                "Source": "/var/docker/volumes/b5f103eb4af4d341bec0815f646ae22ea039b47180bbdc64e3e874c96919c25a/_data",
                "Destination": "/data",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "4d91f6c96a0e",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "6379/tcp": {}
            },
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.10",
                "REDIS_VERSION=4.0.9",
                "REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-4.0.9.tar.gz",
                "REDIS_DOWNLOAD_SHA=df4f73bc318e2f9ffb2d169a922dec57ec7c73dd07bccf875695dbeecd5ec510"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "redis",
            "Volumes": {
                "/data": {}
            },
            "WorkingDir": "/data",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "e522c0eb1166b1b39ea6c3ce71699758c5adc65dcb524217838254a90dc30441",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "6379/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/e522c0eb1166",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "0249f28241c9ad9b662fb7cbbd214b5dcd49f108c0833c0577cdc0e87cd3b3ea",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "7e9e8448f83ff83bc0cb0262aae8b60b1691679f7699752023b3b031aa8686cc",
                    "EndpointID": "0249f28241c9ad9b662fb7cbbd214b5dcd49f108c0833c0577cdc0e87cd3b3ea",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02"
                }
            }
        }
    }
]

得到

"Source": "/var/docker/volumes/b5f103eb4af4d341bec0815f646ae22ea039b47180bbdc64e3e874c96919c25a/_data",

得到了volume在宿主机挂载的地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值