四、Docker基础操作命令
镜像是Docker三大核心概念中最为重要的。Docker运行容器前需要在本地有对应的镜像,如果镜像不存在,Docker则尝试先从镜像仓库中下载然后再运行容器。
获取镜像
语法:
docker [image] pull name[:tag]
name:镜像仓库名
tag:镜像标签
案例:
# 获取制定版本nginx镜像
docker pull nginx:1.17.6
# 获取最新版本nginx镜像
docker pull nginx
查看镜像
-
images列出镜像
docker images # 或 docker image ls
-
tag为镜像添加标签
# 为获取的最近的nginx打上自己的标签 docker tag nginx my_nginx
释义:
nginx:为从仓库获取的nginx镜像
my_nginx:打包为新的nginx
# 为制定版本镜打上自己的标签 docker tag nginx:1.17.6 my_nginx1.17.6
-
inspect查看镜像详细信息
语法
docker [image] inspect
案例
docker image nginx
-
history查看镜像历史
语法
docker [image] history
案例
docker image history nginx
搜索镜像
语法
docker search [option] keyword
[option]
- -f,--filter filter:过滤输出内容
- --format string:格式化输出内容
- --limit int:限制输出结果个数,默认25个
- --no-trunc:不截断输出结果
案例:
搜索官方提供的带php关键字的镜像
docker search --filter=is-official=true php
搜索所有nginx镜像
docker search nginx
删除和清理镜像
语法
docker rmi [options] IMAGE [IMAGE ...] # IMAGE可为标签ID
# 或
docker rm IMAGE [IMAGE]
[options]
- -f 强制删除
- --no-prune 不清理未带标签的父镜像
案例
# 使用标签删除镜像
docker rmi nginx:1.17.6
# 根据image id删除
docker rmi -f f7bb5701a33c
清理镜像
docker image prune [options]
[options]
- -a 删除所有无用镜像
- -filter 只清理符合给定过滤器的镜像
- -f 强制删除镜像,不进行确认提示
docker image prune -
请登录后再评论