使用 docker inspect 命令查看容器挂载的volume的目录
$ sudo docker inspect --format "{{.Volumes}}" redis-master Template parsing error: template: ::: 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----:/etc$ sudo docker inspect redis-master | grep Mount -A
返回结果如下:
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount":
},
"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