iam pulling iamges from dockerhub and i tag them before i push the images to the local registry

  docker, docker-image, docker-registry, dockerhub, python

iam pulling iamges from dockerhub and i tag them before i push the images to the local registry, so i want at the end to delete the original images in my server and the images after tagging, so i only keep what i pushed to my local registry.

here is the tagging code

def tag_images(images, image_names):
    print('====Tagging Images====')

    for image, image_name in zip(images, image_names):
        iname, itag = get_name_and_tag(image_name)
        image.tag(repository=f'{REGISTRY_IP}:{REGISTRY_PORT}/{iname}',
                  tag="local_"+itag)
        print(
            f'Successfully Tagged: {iname}:local_{itag} as {REGISTRY_IP}:{REGISTRY_PORT}/{iname}:local_{itag}')

    print(f'====Tagged {len(images)} Images====')

> here is the deleting code

    def remove_images(image_names, client):
    print(f'====Deleting Original Images====')

    for image_name in image_names:
        iname, itag = get_name_and_tag(image_name)
        client.images.remove(image=f'{iname}:{itag}:{"local_"+itag}', force=True)

    print(f'====Deleted {len(image_names)} Images====')

so i could delete the original image from the server, but i couldnt delete the images after tagging.

any suggestion? thanks in advance

Source: Docker Questions

LEAVE A COMMENT