Docker Community Forums

Share and learn in the Docker community.

How to create "RegistryAuth" for Private Registry Login Credentials

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

Thanks,
Chirag

2 Likes

Don’t know if you’re still waiting (found your thread while searching for another issue =S)

I ran across this: https://docs.docker.com/engine/api/get-started/#pull-images-with-authentication
snippet:

  authConfig := types.AuthConfig{
      Username: "username",
      Password: "password",
  }
  encodedJSON, err := json.Marshal(authConfig)
  if err != nil {
      panic(err)
  }
  authStr := base64.URLEncoding.EncodeToString(encodedJSON)

If you get this far, you may run into my issue:

  • The error goes away
  • No push occurs
  • No data from the returned io.ReadClose

I’ve even put in dummy credentials, invalid ServerAddress, dummy base64 string (heck, I’ve even tried random characters that aren’t even valid base64 strings.)
It seems that as long as you pass in options, it just blindly fails somewhere with no error ever being returned.