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

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

1. 查看镜像基本信息

bash 复制代码
# 查看所有镜像列表
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. 查看镜像详细信息

bash 复制代码
# 查看镜像的完整详细信息
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. 查看镜像分层历史

bash 复制代码
# 查看镜像的构建历史
docker history <镜像名>

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

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

4. 查看镜像内容

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

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

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

bash 复制代码
# 安装 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. 查看镜像的元数据

bash 复制代码
# 查看 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. 实用查询示例

bash 复制代码
# 查看镜像架构(重要!)
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. 组合查询示例

bash 复制代码
# 显示镜像摘要信息
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. 查看远程仓库中的镜像

bash 复制代码
# 使用 skopeo(需要安装)
skopeo inspect docker://ubuntu:latest

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

10. GUI 工具(可选)

  • Portainer:Web 界面管理 Docker
  • Lazydocker:终端 UI
  • Docker Desktop:桌面客户端

最常用的组合命令:

bash 复制代码
# 快速查看镜像核心信息
docker images && echo "---" && docker image inspect <镜像名> --format='架构: {{.Architecture}}, 大小: {{.Size}}, 创建于: {{.Created}}'
相关推荐
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
分布式存储与RustFS3 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
玉&心3 天前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing3 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
赵文宇(温玉)3 天前
CoreDNS的hosts插件的缺行配置导致k8s集群异常
容器·kubernetes·rancher
guo_wen_qiang3 天前
上传本地镜像到harbor中
docker·容器·持续部署
羑悻的小杀马特3 天前
Dockerfile 全景指南:从入门编写dockerfile到生产环境镜像优化实战,一步步带你从啃透制作指令到镜像制作落地!
docker·dockerfile·镜像制作
BianHuanShiZhe3 天前
docker常见命令
docker
正经教主3 天前
【FDE系列】阶段2:Day 43:Docker Compose — 多容器一键编排
人工智能·docker·fde
忆~遂愿3 天前
本地片库怎么在外面打开?Plex + cpolar 搭一套可远程访问的私人影音库
docker·容器