简体   繁体   English

使用 docker golang sdk 删除我的 AWS ECR 映像

[英]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.我正在使用 docker golang sdk https://pkg.go.dev/github.com/docker/docker将我的 docker 镜像推送到 AWS ECR,效果很好。

Now, I want to create an API to delete my AWS ECR images with the same SDK.现在,我想创建一个 API 以使用相同的开发工具包删除我的 AWS ECR 映像。

The issue is ....问题是……

ImagePush method allows registryAuth and that is how it knows where to push my docker images. ImagePush 方法允许 registryAuth,这就是它知道将我的 docker 图像推送到哪里的方式。 But, ImageList & ImageRemove functions does not take registryAuth !但是, ImageList 和 ImageRemove 函数不接受 registryAuth ! Due to this, ImageList function is showing docker images from my local ENV.因此,ImageList 函数显示了来自我本地 ENV 的 docker 图像。

I tried doing registryLogin just before the ImageList call but no luck.我尝试在 ImageList 调用之前执行 registryLogin 但没有运气。 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. client.ImageRemove方法仅从本地主机中删除图像,因此不需要进行身份验证。

To remove image from the ECR Registry, you will need to comunicate with its API.要从 ECR 注册表中删除图像,您需要与其 API 通信。 You can use AWS SDK for Go API : https://docs.aws.amazon.com/sdk-for-go/api/service/ecr/您可以使用AWS SDK for Go APIhttps : //docs.aws.amazon.com/sdk-for-go/api/service/ecr/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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