英文:
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 (
"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)
}
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 :::::::::::::::::::::> error during connect: Post "/images/registry.digitalocean.com/<registry>/<repo>/push?tag=<tag>": unsupported protocol scheme ""
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论