我正在尝试更改图像的存储库名称:
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
如何重命名图像?
要复制图像或重命名现有图像,只需从现有图像创建新标记或存储库。您可以使用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
下面的python代码重命名多个图像,然后推回到新的存储库。这是一个用python3.6编写的docker存储库迁移代码
import docker
client = docker.from_env()
docker_api = docker.APIClient()
images = client.images.list()
for image in images:
try:
if image.tags[0] and '<old repository>' in image.tags[0]:
version = image.tags[0].split("/")[-1]
type(version)
print("version is {}".format(version))
docker_api.tag(image.tags[0],"<new repository>/{}".format(version))
except Exception as Ex:
print(image)
print(Ex)
然后通过下面的shell脚本推送图像
docker images | grep <new repository> | awk '{print $1":"$2}' | xargs -L1 docker push