docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > Docker查看镜像

Docker查看镜像详情的多种常用方法介绍

作者:檀越@新空间

这篇文章主要为大家详细介绍了Docker查看镜像详情的多种常用方法,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以了解一下

查看 Docker 镜像详情的几种常用方法:

1.查看镜像基本信息

# 查看所有镜像列表
docker images

# 详细格式查看
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedAt}}\t{{.Size}}"

# 按特定字段排序
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | sort

2.查看镜像详细信息

# 查看镜像的完整详细信息
docker image inspect <镜像名或ID>

# 查看特定信息(JSON格式)
docker image inspect <镜像名> --format='{{json .}}'

# 提取特定字段
docker image inspect <镜像名> --format='{{.Id}}'
docker image inspect <镜像名> --format='{{.Created}}'
docker image inspect <镜像名> --format='{{.RepoTags}}'
docker image inspect <镜像名> --format='{{.Size}}'
docker image inspect <镜像名> --format='{{.Architecture}}'
docker image inspect <镜像名> --format='{{.Os}}'

3.查看镜像分层历史

# 查看镜像的构建历史
docker history <镜像名>

# 显示完整信息(包括创建命令)
docker history --no-trunc <镜像名>

# 人类可读的格式
docker history --human=true <镜像名>

4.查看镜像内容

# 查看镜像中的文件系统
docker run -it <镜像名> ls -la /

# 或者进入镜像的shell(如果镜像有bash/sh)
docker run -it <镜像名> /bin/bash

5.使用 dive 工具(更详细的分析)

# 安装 dive
# Ubuntu/Debian
wget https://github.com/wagoodman/dive/releases/download/v0.11.0/dive_0.11.0_linux_amd64.deb
sudo apt install ./dive_0.11.0_linux_amd64.deb

# 使用 dive 分析镜像
dive <镜像名>

6.查看镜像的元数据

# 查看 Dockerfile 中的标签
docker image inspect <镜像名> --format='{{json .Config.Labels}}'

# 查看环境变量
docker image inspect <镜像名> --format='{{json .Config.Env}}'

# 查看入口点和命令
docker image inspect <镜像名> --format='{{json .Config.Entrypoint}}'
docker image inspect <镜像名> --format='{{json .Config.Cmd}}'

# 查看工作目录
docker image inspect <镜像名> --format='{{.Config.WorkingDir}}'

# 查看暴露的端口
docker image inspect <镜像名> --format='{{json .Config.ExposedPorts}}'

7.实用查询示例

# 查看镜像架构(重要!)
docker image inspect ubuntu:latest --format='{{.Architecture}}'

# 查看镜像创建时间
docker image inspect ubuntu:latest --format='{{.Created}}'

# 查看镜像大小
docker image inspect ubuntu:latest --format='{{.Size}}' | numfmt --to=iec

# 查看镜像摘要(digest)
docker image inspect ubuntu:latest --format='{{index .RepoDigests 0}}'

# 查看所有信息(格式化输出)
docker image inspect ubuntu:latest | python3 -m json.tool
# 或者使用 jq(需要安装)
docker image inspect ubuntu:latest | jq '.[0]'

8.组合查询示例

# 显示镜像摘要信息
echo "=== 镜像基本信息 ==="
docker image inspect ubuntu:latest --format='镜像ID: {{.Id}}
架构: {{.Architecture}}
创建时间: {{.Created}}
大小: {{.Size}} 字节
标签: {{.RepoTags}}
摘要: {{index .RepoDigests 0}}'

# 查看镜像的层信息
docker image inspect ubuntu:latest --format='{{range .RootFS.Layers}}{{.}}
{{end}}'

9.查看远程仓库中的镜像

# 使用 skopeo(需要安装)
skopeo inspect docker://ubuntu:latest

# 使用 crane(Google的工具)
crane manifest ubuntu:latest

10.GUI 工具(可选)

最常用的组合命令:

# 快速查看镜像核心信息
docker images && echo "---" && docker image inspect <镜像名> --format='架构: {{.Architecture}}, 大小: {{.Size}}, 创建于: {{.Created}}'

到此这篇关于Docker查看镜像详情的多种常用方法介绍的文章就介绍到这了,更多相关Docker查看镜像内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文