docker inspect
option |
说明 |
-f |
指定返回值的模板文件 |
-s |
如果类型为容器,则显示文件总大小 |
–type |
返回指定类型的JSON |
查看数据卷 Mount 并美化输出:
apt-get install jq
docker inspect --format='{{json .Mounts}}' myredis | jq
[
{
"Type": "bind",
"Source": "/redis/data",
"Destination": "/data",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/redis/myredis.conf",
"Destination": "/etc/redis/redis.conf",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
]
rehat系列的,需安装包jq工具
yum -y install epel-release
yum -y install jq
获取容器ip
# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 容器id/容器名
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myredis
172.17.0.2
获取容器mac地址
# docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' 容器id或容器名
docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' myredis
02:42:ac:11:00:02
获取容器日志路径
# docker inspect --format='{{.LogPath}}' 容器id/容器名
docker inspect --format='{{.LogPath}}' myredis
/var/lib/docker/containers/331291f611f2b338a38a0683ac1aed6a51170cd60b94eebf619c7acb74ad7127/331291f611f2b338a38a0683ac1aed6a51170cd60b94eebf619c7acb74ad7127-json.log
查询容器网络信息
# 查看容器所有网络信息
docker inspect --format="{{json .NetworkSettings}}" myredis | jq
# 查看容器端口映射
docker inspect --format="{{json .NetworkSettings.Ports}}" myredis | jq
# 查看容器ip,网关等信息
docker inspect --format="{{json .NetworkSettings.Networks}}" myredis | jq
|