Home > Mobile >  Push locally built docker images to Digital Ocean Container Registry
Push locally built docker images to Digital Ocean Container Registry

Time:10-25

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",
    }

    _, 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 ""

CodePudding user response:

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.

  • Related