使用 docker inspect 命令查看容器挂载的volume的目录html
$ sudo docker inspect --format "{{.Volumes}}" redis-master Template parsing error: template: :1:2: executing "" at <.Volume>: map has no entry for key "Volumes"
结果返回错误,说<.Volumes>为key的map不存在。redis
上网查了查,发现有人说这是版本问题,并找到另外一种方法,代码以下docker
$ sudo docker inspect --format "{{.Config.Volumes}}" redis-master map[/data:{}]
此次结果却是返回了map[/data:{}],可是并无获取到volume挂载在宿主机上的地址。又查了查,获得另外一种方法,代码以下json
ubuntu@ip-172-31-18-10:/etc$ sudo docker inspect redis-master | grep Mount -A 20
返回结果以下:ubuntu
"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, -- "Mounts": [ { "Type": "volume", "Name": "0bf25b5934b6174074f1dcbe6fc41e1551a65d22b6a95a74c125edf28be5841c", "Source": "/var/lib/docker/volumes/0bf25b5934b6174074f1dcbe6fc41e1551a65d22b6a95a74c125edf28be5841c/_data", "Destination": "/data", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], "Config": { "Hostname": "b969f96befd5", "Domainname": "", "User": "", "AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "ExposedPorts": { "6379/tcp": {}
红色部分即为volume在宿主机中挂载的位置tcp
参考:云计算
使用dockerinspect获取数据卷信息遇到的一点问题 - 云计算技术频道 - 红黑联盟 https://www.2cto.com/net/201702/599896.htmlspa