Docker之镜像常用命令

本文介绍了Docker中镜像的基本操作,包括查看、搜索、下载及删除镜像的方法,并详细解析了各命令的使用场景及参数选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

帮助命令

1、docker version    #显示docker版本信息
2、docker info       #显示docker的系统信息,包括镜像和容器数量
3、docker --help     #帮助命令

帮助文档地址:
https://docs.docker.com/engine/reference/commandline/

镜像命令:

docker images 查看所有本地的主机上的镜像

[root@liuyang ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
centos        latest    300e315adb2f   2 months ago    209MB
hello-world   latest    bf756fb1ae65   14 months ago   13.3kB

#解释
REPOSITORY    镜像的仓库源
TAG 		  镜像的标签
IMAGE ID      镜像的ID
CREATED		  镜像的创建时
SIZE		  镜像大小

#可选项

-a  --all  	  查看所有镜像
-q	--quiet   只显示镜像ID
 

docker search搜索镜像

[root@liuyang ~]# docker search mysql
NAME                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                      MySQL is a widely used, open-source relation…   10565     [OK]
mariadb                    MariaDB Server is a high performing open sou…   3947      [OK]
mysql/mysql-server         Optimized MySQL Server Docker images. Create…   774                  [OK]
percona                    Percona Server is a fork of the MySQL relati…   527       [OK]

#可选项
通过条件过滤:
--filter=STARS=3000       	#搜索出来结果的stars大于3000  
	

docker pull 下载镜像

#下载镜像 docker pull 镜像名[:tag]
[root@liuyang ~]# docker pull mysql
//不写tag 默认最新版本latest
Using default tag: latest
latest: Pulling from library/mysql
//分层下载,docker image的核心 联合文件系统
a076a628af6f: Pull complete
f6c208f3f991: Pull complete
88a9455a9165: Pull complete
406c9b8427c6: Pull complete
7c88599c0b25: Pull complete
25b5c6debdaf: Pull complete
43a5816f1617: Pull complete
1a8c919e89bf: Pull complete
9f3cf4bd1a07: Pull complete
80539cea118d: Pull complete
201b3cad54ce: Pull complete
944ba37e1c06: Pull complete
//签名
Digest: sha256:feada149cb8ff54eade1336da7c1d080c4a1c7ed82b5e320efb5beebed85ae8c
Status: Downloaded newer image for mysql:latest
//真实地址
docker.io/library/mysql:latest

**docker.io/library/mysql:latest等价于docker pull mysql**

额外,我们说一下docker的联合文件系统,例如我们下载一个mysql5.7:

[root@liuyang ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
a076a628af6f: Already exists
f6c208f3f991: Already exists
88a9455a9165: Already exists
406c9b8427c6: Already exists
7c88599c0b25: Already exists
25b5c6debdaf: Already exists
43a5816f1617: Already exists
1831ac1245f4: Pull complete
37677b8c1f79: Pull complete
27e4ac3b0f6e: Pull complete
7227baa8c445: Pull complete
Digest: sha256:b3d1eff023f698cd433695c9506171f0d08a8f92a0c8063c1a4d9db9a55808df
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

我们可以看到,下载mysql5.7时,有一部分的文件被共用,减少了内存;
在这里插入图片描述
删除镜像:
docker rmi -f [image_id] 删除指定
docker rmi -f [image_id] [image_id] [image_id] [image_id] 删除多个
docker rmi -f$(docker images -aq) 删除所有
注:image_id能代表唯一标识即可,输三位也行

[root@liuyang ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
mysql         5.7       a70d36bc331a   6 weeks ago     449MB
mysql         latest    c8562eaf9d81   6 weeks ago     546MB
centos        latest    300e315adb2f   2 months ago    209MB
hello-world   latest    bf756fb1ae65   14 months ago   13.3kB
[root@liuyang ~]# docker rmi -f bf756fb
Untagged: hello-world:latest
Untagged: hello-world@sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
[root@liuyang ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
mysql        5.7       a70d36bc331a   6 weeks ago    449MB
mysql        latest    c8562eaf9d81   6 weeks ago    546MB
centos       latest    300e315adb2f   2 months ago   209MB
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘小羊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值