使用 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