将本地构建的Docker镜像推送到Digital Ocean容器注册表。

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

Push locally built docker images to Digital Ocean Container Registry

问题

以下是翻译好的代码:

package main

import (
	"context"
	docker "docker.io/go-docker"
	"docker.io/go-docker/api/types"
	"encoding/base64"
	"encoding/json"
	"fmt"
)

var client docker.Client

func main() {

	ctx := context.Background()

	var token = <digital_ocean_access_token>

	var creds = types.AuthConfig{
		Username:      token,
		Password:      token,
		ServerAddress: "registry.digitalocean.com/<registry>",
	}

	_, err = client.ImagePush(ctx,
		"registry.digitalocean.com/<registry>/<repo>:<tag>",
		types.ImagePushOptions{
			RegistryAuth: registryAuth(creds),
		})

	fmt.Println("stream ::::::::::::::::::::> ", err)

}

func registryAuth(creds types.AuthConfig) string {
	b, err := json.Marshal(&creds)
	if err != nil {
		panic(err)
	}
	return base64.StdEncoding.EncodeToString(b)
}

我的当前代码如上所示:
我能够成功登录到注册表,但在推送注册表时出现了一些问题。
main() 函数显示了以下错误信息:

stream ::::::::::::::::::::>  error during connect: Post "/images/registry.digitalocean.com/<registry>/<repo>/push?tag=<tag>": unsupported protocol scheme ""
英文:
package main

import (
	&quot;context&quot;
	docker &quot;docker.io/go-docker&quot;
	&quot;docker.io/go-docker/api/types&quot;
	&quot;encoding/base64&quot;
	&quot;encoding/json&quot;
	&quot;fmt&quot;
)

var client docker.Client

func main() {

	ctx := context.Background()

	var token = &lt;digital_ocean_access_token&gt;

	var creds = types.AuthConfig{
		Username:      token,
		Password:      token,
		ServerAddress: &quot;registry.digitalocean.com/&lt;registry&gt;&quot;,
	}

	_, err = client.ImagePush(ctx,
		&quot;registry.digitalocean.com/&lt;registry&gt;/&lt;repo&gt;:&lt;tag&gt;&quot;,
		types.ImagePushOptions{
			RegistryAuth: registryAuth(creds),
		})

	fmt.Println(&quot;stream :::::::::::::::::::::&gt; &quot;, err)

}

func registryAuth(creds types.AuthConfig) string {
	b, err := json.Marshal(&amp;creds)
	if err != nil {
		panic(err)
	}
	return base64.StdEncoding.EncodeToString(b)
}

My current code is as above:
I am able to login successfully in the registry, but I am doing something wrong while pushing the registry
the main() call shows me this :

stream :::::::::::::::::::::&gt;  error during connect: Post &quot;/images/registry.digitalocean.com/&lt;registry&gt;/&lt;repo&gt;/push?tag=&lt;tag&gt;&quot;: unsupported protocol scheme &quot;&quot;

答案1

得分: 1

你正在使用的go-docker库已经过时了,你应该将其替换为更新的库https://pkg.go.dev/github.com/docker/docker
这将解决你的unsupported scheme issue问题。

英文:

The go-docker library you are using is outdated and you should replace that with newer library https://pkg.go.dev/github.com/docker/docker.
This will solve your unsupported scheme issue issue.

huangapple
  • 本文由 发表于 2021年10月25日 18:40:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/69706610.html
匿名

发表评论

匿名网友

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

确定