douba1617 2017-03-03 23:35
浏览 83

如何为私人注册表登录凭据创建“ RegistryAuth”

I created a Private Registry using following command:

docker run -d -p 5000:5000 --restart=always --name registry -e REGISTRY_STORAGE_DELETE_ENABLED=true registry:2

I am trying to push Images to this registry using Golang docker client API -> ImagePush

func (cli *Client) ImagePush(ctx context.Context, image string, options types.ImagePushOptions) (io.ReadCloser, error)

When I zoom into ImagePushOptions I see that struct is

type ImagePullOptions struct { All bool RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry PrivilegeFunc RequestPrivilegeFunc }

AnyIdea how to create RegistryAuth String

I tried doing following:

type AuthArgs struct { Username string json:"username" Password string json:"password" Email string json:"email" ServerAddress string json:"serveraddress" }

func() {

m := AuthArgs{"docker", "docker", "", "localhost:5000"} b, err := json.Marshal(m)

fmt.Println(string(b)) encodeStr := base64.StdEncoding.EncodeToString(b)

refStr := "localhost:5000/" + image + ":" + tag fmt.Println(refStr) resp, err := cli.ImagePush(ctx, refStr, types.ImagePushOptions{RegistryAuth: encodeStr }) I am stuck from 3 days, any help would be great

  • 写回答

1条回答 默认 最新

  • douxingmou4533 2017-03-04 00:04
    关注
    auth := types.AuthConfig{
        Username: cfg.User,
        Password: cfg.Passwd,
    }
    authBytes, _ := json.Marshal(auth)
    authBase64 := base64.URLEncoding.EncodeToString(authBytes)
    

    https://github.com/leopoldxx/godocker/blob/master/docker.go

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?