列出本地主机上的镜像,images

docker images

  1. docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. cloudnas/clouddrive latest 992d6e14e603 4 months ago 290MB
  4. hello-world latest feb5d9fea6a5 8 months ago 13.3kB
  • REPOSITORY:仓库名/镜像名
  • TAG:标签(版本号)
    • 同一仓库源存在多个版本,不指定时默认使用最新版latest
  • IMAGE ID:镜像ID
  • CREATED:创建时间
  • SIZE:镜像大小

    OPTIONS可选项

  • -a:列出本地所有镜像(含历史映像层)

  • -q:只显示镜像ID

    查找镜像,search

    docker search [OPTIONS] TERM

    1. docker search hello-world --limit 5
    2. NAME DESCRIPTION STAR S OFFICIAL AUTOMATED
    3. hello-world Hello World! (an example of minimal Dockeriz 1752 [OK]
    4. rancher/hello-world 1
    5. thomaspoignant/hello-world-rest-json This project is a REST hello-world API to bu 1
    6. okteto/hello-world 0
    7. armswdev/c-hello-world Simple hello-world C program on Alpine Linux 0

    NAME:镜像名
    DESCRIPTION:镜像描述
    STARS:点赞数
    OFFICIAL:是否官方
    AUTOMATED:是否自动构建

    OPTIONS可选项

    —limit 数字:限制输出记录数量

    案例

  • 查找hello-world镜像,输出前5个结果

dcker search hello-world --limit 5

拉取镜像,pull

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

案例

  • 没指定TAG,默认下最新的镜像,如:docker pull ubuntu

    1. docker pull redis
    2. Using default tag: latest
    3. latest: Pulling from library/redis
    4. a2abf6c4d29d: Pull complete
    5. c7a4e4382001: Pull complete
    6. 4044b9ba67c9: Pull complete
    7. c8388a79482f: Pull complete
    8. 413c8bb60be2: Pull complete
    9. 1abfd3011519: Pull complete
    10. Digest: sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339
    11. Status: Downloaded newer image for redis:latest
    12. docker.io/library/redis:latest
  • 指定TAG,下载指定版本的镜像,如:docker pull redis:6.0.8

    1. docker pull redis:6.0.8
    2. 6.0.8: Pulling from library/redis
    3. bb79b6b2107f: Pull complete
    4. 1ed3521a5dcb: Pull complete
    5. 5999b99cee8f: Pull complete
    6. 3f806f5245c9: Pull complete
    7. f8a4497572b2: Pull complete
    8. eafe3b6b8d06: Pull complete
    9. Digest: sha256:21db12e5ab3cc343e9376d655e8eabbdbe5516801373e95a8a9e66010c5b8819
    10. Status: Downloaded newer image for redis:6.0.8
    11. docker.io/library/redis:6.0.8

    删除镜像,rmi

    docker rmi [OPTIONS] IMAGE [IMAGE...]

  • 删除单个

docker rmi 镜像id(镜像名也可以)

  • 删除多个

docker rim 镜像名1:TAG 镜像2id

  • 删除全部

docker rmi -f $(docker images -q)

OPTIONS可选项

-f:强制删除

案例

  1. docker rmi 16ecd2772934
  2. Untagged: redis:6.0.8
  3. Untagged: redis@sha256:21db12e5ab3cc343e9376d655e8eabbdbe5516801373e95a8a9e66010c5b8819
  4. Deleted: sha256:16ecd277293476392b71021cdd585c40ad68f4a7488752eede95928735e39df4
  5. Deleted: sha256:3746030fff867eb26a0338ad9d3ab832e6c19c7dc008090bcfa95c7b9f16f505
  6. Deleted: sha256:1274ec54ad17d15ec95d2180cb1f791057e86dfcdfcc18cd58610a920e145945
  7. Deleted: sha256:18d156147e54edec9a927080fdc0a53c4a8814b0c717b36dc62e637363c1a98d
  8. Deleted: sha256:a8f09c4919857128b1466cc26381de0f9d39a94171534f63859a662d50c396ca
  9. Deleted: sha256:2ae5fa95c0fce5ef33fbb87a7e2f49f2a56064566a37a83b97d3f668c10b43d6
  10. Deleted: sha256:d0fe97fa8b8cefdffcef1d62b65aba51a6c87b6679628a2b50fc6a7a579f764c

查看镜像信息,df

docker system df

案例

docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              3                   2                   402.9MB             112.7MB (27%)
Containers          6                   1                   1kB                 0B (0%)
Local Volumes       0                   0                   0B                  0B
Build Cache         0                   0                   0B                  0B

面试题

什么是虚悬镜像?

仓库名/镜像名、标签都是的镜像即虚悬镜像dangling image。
构建镜像时可能会出现的异常情况,遇到虚悬镜像删除即可。