使用Docker Golang SDK删除我的AWS ECR镜像。

huangapple go评论99阅读模式
英文:

Delete my AWS ECR images using docker golang sdk

问题

我正在使用Docker Golang SDK(https://pkg.go.dev/github.com/docker/docker)将我的Docker镜像推送到AWS ECR,效果很好。

现在,我想使用相同的SDK创建一个API来删除我的AWS ECR镜像。

问题是...

ImagePush方法允许使用registryAuth参数,这是它知道将Docker镜像推送到哪里的方式。但是,ImageList和ImageRemove函数不接受registryAuth参数!
因此,ImageList函数显示的是来自我的本地环境的Docker镜像。

我尝试在调用ImageList之前进行registryLogin,但没有成功。
我在这里做错了什么?

body, err := client.RegistryLogin(ctx, creds)
fmt.Println("登录结果", body)

images, err := client.ImageList(ctx,
	types.ImageListOptions{})
fmt.Println("列表错误", err)
英文:

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)

答案1

得分: 1

client.ImageRemove 方法仅从本地主机中删除图像,因此不需要进行身份验证。

要从 ECR Registry 中删除图像,您需要与其 API 进行通信。您可以使用 AWS SDK for Go API
https://docs.aws.amazon.com/sdk-for-go/api/service/ecr/

英文:

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/

huangapple
  • 本文由 发表于 2021年10月27日 20:57:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/69739132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定