Docker< map has no entry for key "Volumes">

1.Docker版本信息

Client:
 Version:   17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    c97c6d6
 Built: Wed Dec 27 20:11:19 2017
 OS/Arch:   linux/amd64

Server:
 Engine:
  Version:  17.12.0-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.2
  Git commit:   c97c6d6
  Built:    Wed Dec 27 20:09:53 2017
  OS/Arch:  linux/amd64
  Experimental: false

2.获取所挂载Volume的情况

在学习《Docker容器与容器云》第二版的2.3搭建你的第一个Docker应用栈中的Redis Master主数据库容器节点的配置的时候,按照书中

sudo docker inspect --format "{{.Volumes}}" bce8

发现并不能得到我们要的信息。

经过一番查阅发现这个命令是用来获取Docker信息的,具体请参考https://docs.docker.com/engine/reference/commandline/inspect/#get-an-instances-ip-address
在终端输入:
sudo docker inspect -h能得到基本用法,


Flag shorthand -h has been deprecated, please use --help

Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects

Options:
  -f, --format string   Format the output using the given Go template
  -s, --size            Display total file sizes if the type is container
      --type string     Return JSON for specified type

输入sudo docker inspect redis-master可以得到这个名为redis-master的信息:

[
    {
        "Id": "846db9b77e210b2b5c109606c2c6a6c74092ef53f80b3b999176f94cad0e11d2",
        "Created": "2018-01-17T07:57:11.33420052Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "/bin/bash"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 5547,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2018-01-17T07:57:12.442575313Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:1e70071f4af45af2cc9e1d1300c675c1ce37ee25a8a5cef1f375db5ed461dbab",
        "ResolvConfPath": "/var/lib/docker/containers/846db9b77e210b2b5c109606c2c6a6c74092ef53f80b3b999176f94cad0e11d2/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/846db9b77e210b2b5c109606c2c6a6c74092ef53f80b3b999176f94cad0e11d2/hostname",
        "HostsPath": "/var/lib/docker/containers/846db9b77e210b2b5c109606c2c6a6c74092ef53f80b3b999176f94cad0e11d2/hosts",
        "LogPath": "/var/lib/docker/containers/846db9b77e210b2b5c109606c2c6a6c74092ef53f80b3b999176f94cad0e11d2/846db9b77e210b2b5c109606c2c6a6c74092ef53f80b3b999176f94cad0e11d2-json.log",
        "Name": "/redis-master",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "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": "shareable",
            "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,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/669d7e6f93d1f09e6740827e3fa27069f88dd7ac2c2ecef3ab1f8bec943dc9e4-init/diff:/var/lib/docker/overlay2/62be0235b532fbf1c1006b3e05a4743fdea7731c2807c70738cc136001c14101/diff:/var/lib/docker/overlay2/c76e6d15b5b7827bc9a0f989a2ab8217d32f64c17333825e1e34d83c82c25ab6/diff:/var/lib/docker/overlay2/24e60b3a20807becdb1984927a764836ea7b928588366a34955b6b9204b63f39/diff:/var/lib/docker/overlay2/311d90a3e3929da6f012c132b20bfbc371c6c05a70e79b9c296183af4217fc74/diff:/var/lib/docker/overlay2/cbbe95b3668fad03ca05fe581beaab6f25d2d9c9d3d17a4a786611ccf2972d4e/diff:/var/lib/docker/overlay2/0efde9431d20180c9b097599bd504a999da9033a093811573ea36d3505b3a6d3/diff",
                "MergedDir": "/var/lib/docker/overlay2/669d7e6f93d1f09e6740827e3fa27069f88dd7ac2c2ecef3ab1f8bec943dc9e4/merged",
                "UpperDir": "/var/lib/docker/overlay2/669d7e6f93d1f09e6740827e3fa27069f88dd7ac2c2ecef3ab1f8bec943dc9e4/diff",
                "WorkDir": "/var/lib/docker/overlay2/669d7e6f93d1f09e6740827e3fa27069f88dd7ac2c2ecef3ab1f8bec943dc9e4/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "6c689ce0a782347d69587b4d09638e87957fef6e3722d497013977fcee62bd0b",
                "Source": "/var/lib/docker/volumes/6c689ce0a782347d69587b4d09638e87957fef6e3722d497013977fcee62bd0b/_data",
                "Destination": "/data",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "846db9b77e21",
            "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.6",
                "REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-4.0.6.tar.gz",
                "REDIS_DOWNLOAD_SHA=769b5d69ec237c3e0481a262ff5306ce30db9b5c8ceb14d1023491ca7be5f6fa"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "redis",
            "Volumes": {
                "/data": {}
            },
            "WorkingDir": "/data",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "38b3c33758c40f92f146bdc08b86e51ee915cbb3d234aa85dd53e475f299e117",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "6379/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/38b3c33758c4",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "8a8fe682469abdd393473cc63bc60801c63521db873872bef2b4ec77f837c41b",
            "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": "39e406efc948325450a052d47d06f913bece3247a07e04eae6c7383ba0cd8432",
                    "EndpointID": "8a8fe682469abdd393473cc63bc60801c63521db873872bef2b4ec77f837c41b",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

可以通过sudo docker inspect --format '{{ range .Mounts }}{{ .Source }}{{ end }}' redis-master获取Volume所挂载情况,得到

/var/lib/docker/volumes/6c689ce0a782347d69587b4d09638e87957fef6e3722d497013977fcee62bd0b/_data

“`
sudo su
cd /var/lib/docker/volumes/6c689ce0a782347d69587b4d09638e87957fef6e3722d497013977fcee62bd0b/_data

现在就可以在主机上编辑Docker的data路径下的文件。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值