使用 docker inspect 命令查看容器掛載的volume的目錄
$ 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不存在。
上網查了查,發現有人說這是版本問題,並找到另一種方法,代碼如下
$ sudo docker inspect --format "{{.Config.Volumes}}" redis-master map[/data:{}]
這次結果倒是返回了map[/data:{}],但是並沒有獲取到volume掛載在宿主機上的地址。又查了查,得到另一種方法,代碼如下
ubuntu@ip-172-31-18-10:/etc$ sudo docker inspect redis-master | grep Mount -A 20
返回結果如下:
"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在宿主機中掛載的位置
參考:
使用dockerinspect獲取數據卷信息遇到的一點問題 - 雲計算技術頻道 - 紅黑聯盟 https://www.2cto.com/net/201702/599896.html