$ docker --help

通过这个命令我们能发现,Docker的命令主要有两部分

  1. Management Commands
  2. Commands:

一、Management Commands

Docker里面的对象进行管理的,比如ImageContainer的管理

我们就可以通过 docker image 来查看如果管理Image

[vagrant@localhost ~]$ docker image

Usage:    docker image COMMAND

Manage images

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.

二、Commands

Commands 是相对于 Management Commands 的一个简便的操作

比如

docker images                       # 相当于 docker image ls
docker ps -a                          # 相当于 docker container ls -a 
docker rm container_id         # 相当于 docker container rm container_id
docker rmi image_id             # 相当于 docker image rm image_id

三、命令推荐

显示所有ContainerID

[vagrant@localhost ~]$ docker container ls -aq
b85cde8b2714
353fa73164ad

删除所有的Container

docker rm $(docker container ls -aq)

删除所有状态为 exited 的容器,-f就是筛选过滤的意思

docker rm $(docker container ls -f "status=exited" -q)