Docker image 命令
2018-01-25 by dongnan
简介
Docker 从 1.13.1 版本开始支持 image 子命令,新命令集成了list,rm,build,tag,push,pull,
等功能,而在 docker 1.12.5 (含)之前的版本,这些命令是相互独立且分开使用的,例如 列出镜像 images ,删除镜像 rmi ,详细参考这里 。
旧版
docker images  -h
# ...省略
List images
Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print images using a Go template
      --help            Print usage
      --no-trunc        Don't truncate output
  -q, --quiet           Only show numeric IDs 
新版
docker image  -h
# ...省略
Manage images
Options:
      --help   Print usage
Commands:
  build       Build an image from a Dockerfile
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Display detailed information on one or more images
  load        Load an image from a tar archive or STDIN
  ls          List images
  prune       Remove unused images
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rm          Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
使用过滤器
默认情况下不加任何参数, docker image 会列出所有顶级镜像,但是有时候我们只希望列出部分镜像;
列出虚悬镜像
docker image ls -f dangling=true
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
hub.zongming.net/demo/irm-py   <none>              2b3b644b633a        2 days ago          3.06GB 
删除虚悬镜像
docker rmi `docker image ls -f dangling=true -q`