Home > Enterprise >  Delete my AWS ECR images using docker golang sdk
Delete my AWS ECR images using docker golang sdk

Time:10-29

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)

CodePudding user response:

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/

  • Related