简体   繁体   中英

Delete my AWS ECR images using docker golang sdk

I am using docker golang sdk https://pkg.go.dev/github.com/docker/docker to push my docker images to AWS ECR, which is working great.

Now, I want to create an API to delete my AWS ECR images with the same SDK.

The issue is ....

ImagePush method allows registryAuth and that is how it knows where to push my docker images. But, ImageList & ImageRemove functions does not take registryAuth ! Due to this, ImageList function is showing docker images from my local ENV.

I tried doing registryLogin just before the ImageList call but no luck. What am I doing wrong here ?

body, err := client.RegistryLogin(ctx, creds)
fmt.Println("login body", body)

images, err := client.ImageList(ctx,
    types.ImageListOptions{})
fmt.Println("list err", err)

The client.ImageRemove method, removes the image only from your local host, so it doesen't need to authenticate.

To remove image from the ECR Registry, you will need to comunicate with its API. You can use AWS SDK for Go API : https://docs.aws.amazon.com/sdk-for-go/api/service/ecr/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM