【问题标题】:Push locally built docker images to Digital Ocean Container Registry将本地构建的 docker 镜像推送到 Digital Ocean Container Registry
【发布时间】:2025-12-21 05:40:11
【问题描述】:
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 ""

【问题讨论】:

  • 尝试在域前添加http://https://,以适用者为准。
  • @Z.Kosanovic,是的,在服务器地址中尝试过,没用!同样的错误:(

标签: docker go digital-ocean


【解决方案1】:

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

【讨论】: