Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Python3.6 Rename and Push Docker Images into New Repository

Below python code changes the repository names:


client = docker.from_env()
docker_api = docker.APIClient()
images = client.images.list()
for image in images:
    try:
        if image.tags[0] and '<image you want to rename>' 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) 
After Renaming the images you can push these images in new repo:

docker images | grep <new repository> | awk '{print $1":"$2}' | xargs -L1 docker push