列出本地主机上的镜像,images
docker images
docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcloudnas/clouddrive latest 992d6e14e603 4 months ago 290MBhello-world latest feb5d9fea6a5 8 months ago 13.3kB
- REPOSITORY:仓库名/镜像名
- TAG:标签(版本号)
- 同一仓库源存在多个版本,不指定时默认使用最新版latest
- IMAGE ID:镜像ID
- CREATED:创建时间
-
OPTIONS可选项
-a:列出本地所有镜像(含历史映像层)
-
查找镜像,search
docker search [OPTIONS] TERMdocker search hello-world --limit 5NAME DESCRIPTION STAR S OFFICIAL AUTOMATEDhello-world Hello World! (an example of minimal Dockeriz… 1752 [OK]rancher/hello-world 1thomaspoignant/hello-world-rest-json This project is a REST hello-world API to bu… 1okteto/hello-world 0armswdev/c-hello-world Simple hello-world C program on Alpine Linux… 0
NAME:镜像名
DESCRIPTION:镜像描述
STARS:点赞数
OFFICIAL:是否官方
AUTOMATED:是否自动构建OPTIONS可选项
案例
查找hello-world镜像,输出前5个结果
dcker search hello-world --limit 5
拉取镜像,pull
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
案例
没指定TAG,默认下最新的镜像,如:
docker pull ubuntudocker pull redisUsing default tag: latestlatest: Pulling from library/redisa2abf6c4d29d: Pull completec7a4e4382001: Pull complete4044b9ba67c9: Pull completec8388a79482f: Pull complete413c8bb60be2: Pull complete1abfd3011519: Pull completeDigest: sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339Status: Downloaded newer image for redis:latestdocker.io/library/redis:latest
指定TAG,下载指定版本的镜像,如:docker pull redis:6.0.8
docker pull redis:6.0.86.0.8: Pulling from library/redisbb79b6b2107f: Pull complete1ed3521a5dcb: Pull complete5999b99cee8f: Pull complete3f806f5245c9: Pull completef8a4497572b2: Pull completeeafe3b6b8d06: Pull completeDigest: sha256:21db12e5ab3cc343e9376d655e8eabbdbe5516801373e95a8a9e66010c5b8819Status: Downloaded newer image for redis:6.0.8docker.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可选项
案例
docker rmi 16ecd2772934Untagged: redis:6.0.8Untagged: redis@sha256:21db12e5ab3cc343e9376d655e8eabbdbe5516801373e95a8a9e66010c5b8819Deleted: sha256:16ecd277293476392b71021cdd585c40ad68f4a7488752eede95928735e39df4Deleted: sha256:3746030fff867eb26a0338ad9d3ab832e6c19c7dc008090bcfa95c7b9f16f505Deleted: sha256:1274ec54ad17d15ec95d2180cb1f791057e86dfcdfcc18cd58610a920e145945Deleted: sha256:18d156147e54edec9a927080fdc0a53c4a8814b0c717b36dc62e637363c1a98dDeleted: sha256:a8f09c4919857128b1466cc26381de0f9d39a94171534f63859a662d50c396caDeleted: sha256:2ae5fa95c0fce5ef33fbb87a7e2f49f2a56064566a37a83b97d3f668c10b43d6Deleted: sha256:d0fe97fa8b8cefdffcef1d62b65aba51a6c87b6679628a2b50fc6a7a579f764c
查看镜像信息,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
面试题
什么是虚悬镜像?
仓库名/镜像名、标签都是
构建镜像时可能会出现的异常情况,遇到虚悬镜像删除即可。
