Docker 镜像 的常用命令介绍

拉取镜像

shell 复制代码
$ docker pull imageName[:tag]

[:tag] tag 不写时,拉取的 是 latest 的镜像


查看镜像

查看所有本地镜像

shell 复制代码
docker images
or 
docker images -a


查看完整的镜像的数字签名

shell 复制代码
docker images --digests

查看完整的镜像ID

shell 复制代码
docker images --no-trunc

只查看所有的镜像ID

shell 复制代码
docker images -q

只查看某个仓库的镜像

shell 复制代码
docker images repositoryName

只查看某个仓库的某个版本的镜像

shell 复制代码
docker images repositoryName:tag

过滤查看(了解即可)

shell 复制代码
# 查看 日期在 tomcat:8.5 之后的镜像
docker images -f since=tomcat:8.5
# 查看 日期在 tomcat:8.5 之前的镜像
docker images -f before=tomcat:8.5
# 查看 tomcat 仓库的所有 版本的镜像 : 但是只支持官方的镜像
docker images -f reference=tomcat:*

查找镜像

从 docker hub 官网查找(不能用)

由于国内网络的问题,这个命令是不能用的

shell 复制代码
docker search repositoryName

指定国内镜源像查找(可用)

docker.1ms.run 就是一个国内的镜像加速地址,挺好用。

shell 复制代码
docker search docker.1ms.run/mysql

限制查询的条数

--limit=N 选项 限制返回的条数

shell 复制代码
docker search --limit=5 docker.1ms.run/mysql

过滤搜索

-f is-official=true : 过滤官方的镜像

shell 复制代码
docker search -f is-official=true docker.1ms.run/mysql

-f stars=N : 过滤 stars 数量超过N的

shell 复制代码
docker search -f stars=100 docker.1ms.run/mysql

-f is-automated=true : 过滤自动构建的镜像,过时的一个方法,不建议使用。

shell 复制代码
docker search -f is-automated=true docker.1ms.run/mysql

删除镜像

删除镜像

当删除多个的时候,通过空格隔开即可

shell 复制代码
docker rmi repository:tag [其他的镜像]
or
docker rmi imageId [其他的镜像ID]

强制删除

shell 复制代码
docker rmi -f repository:tag
or
docker rmi -f imageId

删除所有镜像

通过引用 docker images -q 命令的返回值,

实现删除所有的镜像。

shell 复制代码
docker rmi -f $(docker images -q)

删除过程会提示删除的镜像分层。

导入导出镜像

导出镜像

就是把镜像到处到一个 tar 的压缩文件中,方便传输。
注意 : 不要使用 imageID ,存在 元数据丢失的问题,即还原后 没有 镜像的名称和 tag 了。

shell 复制代码
# 语法格式
docker save -o targetName.tar repository:tag

# 实际演示一个 : 把本地所有的镜像都打包
docker save -o abc.tar mysql:8.0.41

导入镜像

就是将 tar 文件解压,还原成原来的镜像。

shell 复制代码
# 语法格式
$ docker load -i targetName.tar

# 实际演示一个
$ docker load -i abc.tar

查看镜像的json文件内容

shell 复制代码
docker inspect mysql:8.0.41
相关推荐
fetasty14 小时前
rustfs加picgo图床搭建
docker
蝎子莱莱爱打怪1 天前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
碳基沙盒2 天前
OpenClaw 多 Agent 配置实战指南
运维
小p2 天前
docker学习7:docker 容器的通信方式
docker
小p2 天前
docker学习5:提升Dockerfile水平的5个技巧
docker
小p2 天前
docker学习3:docker是怎么实现的?
docker
小p4 天前
docker学习: 2. 构建镜像Dockerfile
docker
小p4 天前
docker学习: 1. docker基本使用
docker
蝎子莱莱爱打怪5 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
崔小汤呀5 天前
Docker部署Nacos
docker·容器