Skip to content

镜像操作 ​

1 docker images ​

列出镜像列表

bash
docker images 
REPOSITORY                         TAG           IMAGE ID       CREATED        SIZE
guacamole/guacd                    latest        ee0b218233ff   9 days ago     271MB
golang                             1.16-alpine   7e352955f83c   5 weeks ago    302MB
alpine                             latest        c059bfaa849c   7 weeks ago    5.59MB

列出的镜像列说明:

  • REPOSITORY:表示镜像的仓库源
  • TAG:镜像的标签,同一仓库源可以有多个 TAG,代表这个仓库源的不同个版本
  • IMAGE ID:镜像ID
  • CREATED:镜像创建时间,不是我们pull的时间
  • SIZE:镜像大小

搜索需要的镜像:docker search 镜像名字

--limit : 只列出N个镜像,默认25个 docker search --limit 5 redis

3 docker pull ​

拉取指定镜像:docker pull 镜像名字[:TAG] 没有TAG就是最新版,docker pull 镜像名字:latest

4 docker rmi ​

删除镜像:

  • 单个:docker rmi -f 镜像ID
  • 多个:docker rmi -f 镜像名1:TAG 镜像名2:TAG
  • 全部:docker rmi -f $(docker images -qa)

删除所有未打 dangling 标签的镜像:docker rmi $(docker images -q -f dangling=true)

5 docker system df ​

查看镜像/容器/数据卷所占的空间

bash
docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          7         4         3.915GB   374.5MB (9%)
Containers      4         4         2.392MB   0B (0%)
Local Volumes   2         1         0B        0B
Build Cache     0         0         0B        0B

注意

有的时间我们会看见有些镜像的名称是none,TAG也是none,这种情况我们一般称幽灵镜像,一般处理方式是直接删除,一般是我们自己制作镜像的时候发生