知识点6--Docker的镜像命令
本篇给大家介绍Docker的镜像命令。
说一点:看我写的容器命令和镜像命令博文,要灵活传参,名字、id、别名,大家要灵活使用,不要我下面写什么大家就用什么。包括不同的参数,我不可能把所有的都笛卡尔出来,自己要思考,知道有什么用,就可以自己去组合
1、查看本地有那些镜像,默认只展示镜像的最终层,如果你想要同时展示出中间层就加-a
参数
[root@hdp3 ~] docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 14 months ago 13.3kB
REPOSITORY
:镜像名称
TAG
:镜像的版本标签
IMAGE ID
:镜像的ID
CREATED
:镜像创建时间
SIZE
:镜像大小
2、展示当前已有镜像的ID,默认只有最终层,如果你想同时展示中间层则使用-qa
,
[root@hdp3 ~] docker images -q
feb5d9fea6a5
3、展示镜像的同时展示摘要
[root@hdp3 ~] docker images --digests
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
hello-world latest sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f feb5d9fea6a5 14 months ago 13.3kB
说明一点,Docker镜像的摘要digest
它其实是对 docker 镜像的各个分层,进行打包后,对打包结果进行哈希运算,得到的64位 sha256 的哈希值。这个值一旦生成,就无法改变。这涉及到镜像的拉取方式,镜像有三种拉取方式:使用镜像名拖取、使用标签拖取、使用digest拖取
4、查看镜像的完整信息
[root@hdp3 ~]# docker images --no-trunc
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412 14 months ago 13.3kB
这里重点说明IMAGE ID是你本地仓库镜像的一个标识,DIGEST ID是这个镜像的官方全网唯一ID
5、用命令行的方式查找远程仓库的某个镜像,这个命令和你在官网页面查找镜像是一样的逻辑,该命令接收二个参数:--no-trunc
展示完整的镜像描述,这里注意查镜像时展示的完整描述就是我们普通理解中的说明,而你查本地镜像完整信息时说的是镜像的完整IMAGE ID,不要搞混、-f
过滤条件不同条件用空格隔开,支持过滤表达式、名字字符串
[root@hdp3 ~] docker search hello-world
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
hello-world Hello World! (an example of minimal Dockeriz… 1920 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demonstr… 153
tutum/hello-world Image to test docker deployments. Has Apache… 90 [OK]
dockercloud/hello-world Hello World! 20 [OK]
crccheck/hello-world Hello World web server in under 2.5 MB 15 [OK]
vad1mo/hello-world-rest A simple REST Service that echoes back all t… 5 [OK]
rancher/hello-world 4
ppc64le/hello-world Hello World! (an example of minimal Dockeriz… 2
thomaspoignant/hello-world-rest-json This project is a REST hello-world API to bu… 2
ansibleplaybookbundle/hello-world-db-apb An APB which deploys a sample Hello World! a… 2 [OK]
ansibleplaybookbundle/hello-world-apb An APB which deploys a sample Hello World! a… 1 [OK]
strimzi/hello-world-producer 0
armswdev/c-hello-world Simple hello-world C program on Alpine Linux… 0
strimzi/hello-world-consumer 0
businessgeeks00/hello-world-nodejs 0
koudaiii/hello-world 0
freddiedevops/hello-world-spring-boot 0
strimzi/hello-world-streams 0
garystafford/hello-world Simple hello-world Spring Boot service for t… 0 [OK]
tacc/hello-world 0
tsepotesting123/hello-world 0
kevindockercompany/hello-world 0
dandando/hello-world-dotnet 0
okteto/hello-world 0
rsperling/hello-world3 0
NAME
:镜像名字
DESCRIPTION
:说明
STARS
:点赞数
OFFICIAL
:该镜像对于你查找的目的来说是否是官方的
AUTOMATED
:是否是自动构建的
6、下载一个镜像,下载的时候通常要先查你要下载那个,并且下载的时候是否需要指定标签,如果不指定标签,则默认标签为:latest
,也就是最新版,另外提一点通过名字下载很可能在某个极端情况下下载不到你希望的镜像,发生这种情况就用Digest ID下载
[root@hdp3 ~] docker search --helpUsage: docker search [OPTIONS] TERMSearch the Docker Hub for imagesOptions:-f, --filter filter Filter output based on conditions provided--format string Pretty-print search using a Go template--limit int Max number of search results (default 25)--no-trunc Don't truncate output[root@hdp3 ~] docker search -f stars=30 tomcat --limit 1
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 3448 [OK] [root@hdp3 ~] docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
0e29546d541c: Pull complete
9b829c73b52b: Pull complete
cb5b7ae36172: Pull complete
6494e4811622: Pull complete
668f6fcc5fa5: Pull complete
dc120c3e0290: Pull complete
8f7c0eebb7b1: Pull complete
77b694f83996: Pull complete
0f611256ec3a: Pull complete
4f25def12f23: Pull complete
Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest[root@hdp3 ~] docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest fb5657adc892 11 months ago 680MB
hello-world latest feb5d9fea6a5 14 months ago 13.3kB
如果你知道一个镜像的Digest ID也可以指定Digest ID下载
[root@hdp3 ~] docker pull hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
docker.io/library/hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f: Pulling from library/hello-world
2db29710123e: Already exists
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
docker.io/library/hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f[root@hdp3 ~] docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world <none> feb5d9fea6a5 14 months ago 13.3kB
7、删除本地的某个镜像,删除的时候和下载一样考虑是否需要标签,默认:latest
[root@hdp3 ~] docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest fb5657adc892 11 months ago 680MB
hello-world latest feb5d9fea6a5 14 months ago 13.3kB[root@hdp3 ~] docker rmi tomcat:latest
Untagged: tomcat:latest
Untagged: tomcat@sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Deleted: sha256:fb5657adc892ed15910445588404c798b57f741e9921ff3c1f1abe01dbb56906
Deleted: sha256:2b4d03a9ce5e200223e5c398d4739d23dd19ad0d6e692cfc65ba3a8fae838444
Deleted: sha256:35c5ea12be1face90896b3a52afc28433885c4448a6c5cfe07561f82365cd18e
Deleted: sha256:6830091c111746b7534960d17f6c156be45d8dcfe0defb06bd427ef38bf49aae
Deleted: sha256:ea82d4efcdfa1c039d722a5a9613c18d3c3a84fbba8efae5e7f13cb3b4ec379f
Deleted: sha256:79a6c362c6b1a580d2d8d33f6d860d45c530f34ff7c0441d36b61aceefdfd656
Deleted: sha256:1788a74c5c86e769f61cd615269eba11c3d7648eac4a85a1ffd2840427820a2f
Deleted: sha256:cbce712ed17923285239f9d9c0528984aef065b7413d68a0290e2c8eecc98f4a
Deleted: sha256:aa56d037ee5925ebf11127c3e1f617874c4ce8bae6b6af7d132b7f7a4a606e6f
Deleted: sha256:97e5f44efb543d466c5847602654a8cb22c9466b61d04988d47ec44b197ea874
Deleted: sha256:11936051f93baf5a4fb090a8fa0999309b8173556f7826598e235e8a82127bce[root@hdp3 ~] docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 14 months ago 13.3kB
上面正常删除时没有问题的,但是如果你删除的是一个存在对应容器的镜像,就会报错
[root@hdp3 ~] docker rmi hello-world
Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 4f16af718bfd is using its referenced image feb5d9fea6a5
此时你要删除则添加-f
参数
[root@hdp3 ~] docker rmi hello-world -f
Untagged: hello-world:latest
Untagged: hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
如果你有多个同名或者相似名称的镜像,你可以通过本地镜像的IMAGE ID
去删除,注意这里说的ID是docker images
查出的ID,而镜像的DIGEST ID
是用来下载的
[root@hdp3 ~] docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest fb5657adc892 11 months ago 680MB[root@hdp3 ~] docker rmi fb5657adc892
Untagged: tomcat:latest
Untagged: tomcat@sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Deleted: sha256:fb5657adc892ed15910445588404c798b57f741e9921ff3c1f1abe01dbb56906
Deleted: sha256:2b4d03a9ce5e200223e5c398d4739d23dd19ad0d6e692cfc65ba3a8fae838444
Deleted: sha256:35c5ea12be1face90896b3a52afc28433885c4448a6c5cfe07561f82365cd18e
Deleted: sha256:6830091c111746b7534960d17f6c156be45d8dcfe0defb06bd427ef38bf49aae
Deleted: sha256:ea82d4efcdfa1c039d722a5a9613c18d3c3a84fbba8efae5e7f13cb3b4ec379f
Deleted: sha256:79a6c362c6b1a580d2d8d33f6d860d45c530f34ff7c0441d36b61aceefdfd656
Deleted: sha256:1788a74c5c86e769f61cd615269eba11c3d7648eac4a85a1ffd2840427820a2f
Deleted: sha256:cbce712ed17923285239f9d9c0528984aef065b7413d68a0290e2c8eecc98f4a
Deleted: sha256:aa56d037ee5925ebf11127c3e1f617874c4ce8bae6b6af7d132b7f7a4a606e6f
Deleted: sha256:97e5f44efb543d466c5847602654a8cb22c9466b61d04988d47ec44b197ea874
Deleted: sha256:11936051f93baf5a4fb090a8fa0999309b8173556f7826598e235e8a82127bce[root@hdp3 ~] docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
如果你要一次性删除多个,则用空格隔开就可,这点就不演示了。
如果某一天你需要把所有镜像全部删除,你可以运行如下命令
[root@hdp3 ~] docker rmi -f $(docker images -q)
Untagged: hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
知识点6--Docker的镜像命令相关推荐
- 39、Docker(镜像命令)
Docker(镜像命令) 镜像操作命令: *docker images 查看镜像 *docker rmi 删除镜像 *docker pull 拉取镜像 *docker save 保存镜像为一个压缩包 ...
- docker删除镜像命令_第三章 Docker常用命令之镜像命令
3.2 镜像命令: docker images 列出本机所有镜像docker images -a 列出本机所有镜像,包含中间映像层docker images -q 列出本机所有镜像的iddocker ...
- docker:镜像命令
简介 镜像相当于一个程序,容器相当于一个进程. 容器就是运行着的镜像. 镜像由多个层组成,每层叠加之后,从外部看来就是一个独立的镜像.镜像内部是一个精简的操作系统,同时内部还包含应用运行所必须的文件和 ...
- docker 导出镜像命令
Docker 导出镜像的命令是: docker save<image_name> -o <output_file> 其中,<image_name> 是你要导出的镜像 ...
- 【docker常用镜像命令总结,持续更新中... 建议收藏!】
1.reids redis的启动命令 docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -v /mydata/redis ...
- docker查询镜像命令_Docker镜像相关命令
1.搜索镜像 可使用 docker search命令搜索存放在 Docker Hub中的镜像.执行该命令后, Docker就会在Docker Hub中搜索含有 java这个关键词的镜像仓库. # do ...
- Docker 03 镜像命令
参考源 https://www.bilibili.com/video/BV1og4y1q7M4?spm_id_from=333.999.0.0 https://www.bilibili.com/vid ...
- Docker 的 镜像的常用命令
学习自:[狂神说Java]Docker最新超详细版教程通俗易懂_哔哩哔哩_bilibili docker 的常用命令 docker version docker info #信息 docker com ...
- Docker help命令和镜像命令、虚悬镜像dangling images的创建和删除
目录 1. help命令 1.1 docker help命令 1.2 docker具体命令的help示例 2. 镜像命令 2.1 docker images---查看本地镜像 2.2 docker s ...
最新文章
- TB级微服务海量日志监控平台
- Springboot+Thymeleaf+layui框架的配置与使用
- 睡前刷8分钟手机,身体兴奋1小时
- iPhone用户状告App厂商手脚不干净,偷窥我电脑剪切板干什么
- 面试题 10.01. 合并排序的数组
- 【面经】回顾19秋招面经
- java添加日志打印出sql语句_实现Mybatis在控制台和日志文件中打印SQL语句
- Ubuntu 12.04下Proftpd FTP服务器配置
- php对象在内存中的分配
- JS判断不同的浏览器和版本,提示浏览器版本过低,兼容IE8到IE11
- Godot Label 节点
- 仿Tumblr点赞心破碎动画
- linux登录认证过程,Linux的SSH免密登录认证过程研究
- 抖音Android无障碍开发知识总结
- ros1-gazebo创建世界和机器人模型(单线雷达、多线雷达、相机)
- juju based openstack upgrade (by quqi99)
- 论程序员成长中不可避免的选择,薪资与积累
- SMT 常用术语解释
- 解决Python打开文件报错UnicodeDecodeError: 'gbk' codec can't decode byte
- 腾讯微博qq说说备份导出工具_QQ空间导出助手 – 日志、相册、视频、留言板、QQ 好友列表等...
热门文章
- 创立了维基百科的人,竟然要颠覆维基百科?| 独家
- 去中心化身份一般见解
- Serverless,实现 IoT 设备运行状态缓存到Redis方案
- MSM8974平台功耗问题----通话过程启动Speaker导致功耗异常
- 上千年等待终唤“热潮“,汉服的未来会一帆风顺吗?
- OpenCV玩九宫格数独(零)——预告篇
- 接口,类与接口的关系,接口与抽象类的区别
- [转帖]PAT 计算机程序设计能力考试
- 参考文献中各字母的含义
- 2022四月——芝麻西瓜这样简单的道理却也让人......