我正在尝试更改图像的存储库名称:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
server latest d583c3ac45fd 26 minutes ago 685.5 MB
因此,我想将名称服务器更改为类似myname/server的名称:
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
myname/server latest d583c3ac45fd 26 minutes ago 685.5 MB
我该怎么做?
如何重命名图像?
要复制图像或重命名现有图像,只需从现有图像创建新标记或存储库。您可以使用docker标记命令执行此操作。
syntax/command: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
#=> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-git latest c0aaaba33a60 18 hours ago 208MB
docker tag ubuntu-git:latest ubuntu-git:latest-new-tag
#=> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-git latest c0aaaba33a60 18 hours ago 208MB
ubuntu-git latest-new-tag c0aaaba33a60 18 hours ago 208MB
截至2022年,没有一个顶级答案真正明确地说明了某人如何能够轻松地“重命名”给定存储库的每个标签,以便将一个存储库的标签迁移到另一个存储。Bensuprac的回答让我找到了这个oneliner,它帮助我将GitLab注册迁移到Quay。
首先,如果需要,您可以使用以下命令一次拉取所有图像:
docker pull oldregistry.example.com/my-image --all-tags
单线图:
docker image list oldregistry.example.com/my-image --format "{{.Tag}}" | xargs -r -P$(nproc) -I {} docker image tag oldregistry.example.com/my-image:{} newregistry.example.com/my-image:{}
最后:
docker push newregistry.example.com/my-image --all-tags
如果需要,不要忘记在pull/push命令之前使用docker登录。
docker image tag server:latest myname/server:latest
or
docker image tag d583c3ac45fd myname/server:latest
标签只是完整图像名称(d583c3ac45fd…)的人类可读别名。
因此,您可以根据自己的喜好将它们中的任意多个与同一图像关联。如果您不喜欢旧名称,可以在重新标记后将其删除:
docker rmi server
这只会删除别名/标记。由于d583c3ac45fd具有其他名称,因此不会删除实际图像。