Docker tag命令
本文将介绍docker tag命令。
标记本地镜像,将其归入某一仓库。帮助信息如下:
hxstrive@localhost:~/Desktop$ docker tag --help
Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE其中:
SOURCE_IMAGE 表示源镜像名称
TARGET_IMAGE 表示目标镜像名称
[:TAG] 表示TAG名称,这是可选的
实例1:为指定的容器(不指定tag,默认为latest)生成一个标记。
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
centos latest 9f38484d220f 4 months ago 202MB
hello-world latest fce289e99eb9 6 months ago 1.84kB
[root@localhost ~]# docker tag ubuntu myubuntu:v16
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myubuntu v16 4c108a37151f 4 weeks ago 64.2MB
ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
centos latest 9f38484d220f 4 months ago 202MB
hello-world latest fce289e99eb9 6 months ago 1.84kB首先使用“docker images”查看本机docker存有哪些镜像;使用“docker tag ubuntu myubuntu:v16”或“docker tag ubuntu:latest myubuntu:v16”去创建一个新的tag;然后再次使用“docker images”查看镜像列表。
实例2:为指定的容器和版本生成一个用户自定义的标记。
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
centos 6.7 9f1de3c6ad53 4 months ago 191MB
[root@localhost ~]# docker tag centos:6.7 mycentos:v6.7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
centos 6.7 9f1de3c6ad53 4 months ago 191MB
mycentos v6.7 9f1de3c6ad53 4 months ago 191MB上面我们有一个centos:6.7的镜像,使用“docker tag centos:6.7 mycentos:v6.7”生成一个新的标记“mycentos:v6.7”镜像。
实例3:删除自定义的tag。下面将删除“mycentos:v6.7”自定义的tag。
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
centos 6.7 9f1de3c6ad53 4 months ago 191MB
mycentos v6.7 9f1de3c6ad53 4 months ago 191MB
[root@localhost ~]# docker rmi mycentos
Error: No such image: mycentos
[root@localhost ~]# docker rmi mycentos:v6.7
Untagged: mycentos:v6.7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
centos 6.7 9f1de3c6ad53 4 months ago 191MB注意:上面直接使用“docker rmi mycentos”语句删除镜像失败了,因为该语句默认将删除latest的版本,但是我们没有改版本的镜像。需要我们手动指定版本“docker rmi mycentos:v6.7”。
总结:使用docker tag创建的目标和一般的docker镜像没有什么区别,也能使用docker rmi、docker run进行操作。
成熟不是人的心变老,而是泪在眼眶里打转还能微笑。
说说我的看法 -
还可使用 Gitee / GitHub 账号一键登录,与大家分享你的观点
立即登录
全部评论()
没有评论
- Docker安装Oracle 19c企业版详细教程:从拉取镜像到DBeaver连接数据库
- Docker 安装 IBM DB2 数据库教程:从快速安装到可视化连接(DBeaver)
- Docker 安装 RabbitMQ 消息中间件详细步骤(含管理界面配置与验证)
- Docker 安装 SQL Server 2022 最新版:最简单稳定、国内极速的完整教程
- Docker安装Jupyter服务:Ubuntu/CentOS一键部署Jupyter Lab教程
- Docker安装MongoDB详细步骤:从拉取镜像到数据持久化完整指南
- 如何在 Debian 中安装 Docker 容器引擎
- docker 安装 Qdrant 向量数据库
- Ubuntu22 LTS 使用 Docker 28.0.1 运行 tomcat 8.5 出现中文乱码
- IDEA 连接到远程服务器 Docker