func NewAuthConfigurationsFromDockerCfg() (*AuthConfigurations, error) {
	err := fmt.Errorf("no docker configuration found")
	var auths *AuthConfigurations
	pathsToTry := cfgPaths(os.Getenv("DOCKER_CONFIG"), os.Getenv("HOME"))
	for _, path := range pathsToTry {
		auths, err = NewAuthConfigurationsFromFile(path)
		if err == nil {
			return auths, nil
		}
	}
	return auths, err
}
NewAuthConfigurationsFromDockerCfg returns AuthConfigurations from
system config files. The following files are checked in the order listed:
- $DOCKER_CONFIG/config.json if DOCKER_CONFIG set in the environment,
- $HOME/.docker/config.json
- $HOME/.dockercfg
package docker
import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path"
	"strings"
)
var ErrCannotParseDockercfg = errors.New("failed to read authentication from dockercfg")
type AuthConfiguration struct {
	Username      string `json:"username,omitempty"`
	Password      string `json:"password,omitempty"`
	Email         string `json:"email,omitempty"`
	ServerAddress string `json:"serveraddress,omitempty"`
	IdentityToken string `json:"identitytoken,omitempty"`
	RegistryToken string `json:"registrytoken,omitempty"`
}
func (c AuthConfiguration) isEmpty() bool {
	return c == AuthConfiguration{}
}
func (c AuthConfiguration) headerKey() string {
	return "X-Registry-Auth"
}
type AuthConfigurations struct {
	Configs map[string]AuthConfiguration `json:"configs"`
}
func (c AuthConfigurations) isEmpty() bool {
	return len(c.Configs) == 0
}
func (c AuthConfigurations) headerKey() string {
	return "X-Registry-Config"
}
type AuthConfigurations119 map[string]AuthConfiguration
func (c AuthConfigurations119) isEmpty() bool {
	return len(c) == 0
}
func (c AuthConfigurations119) headerKey() string {
	return "X-Registry-Config"
}
type dockerConfig struct {
	Auth          string `json:"auth"`
	Email         string `json:"email"`
	IdentityToken string `json:"identitytoken"`
	RegistryToken string `json:"registrytoken"`
}
func NewAuthConfigurationsFromFile(path string) (*AuthConfigurations, error) {
	r, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	return NewAuthConfigurations(r)
}
func cfgPaths(dockerConfigEnv string, homeEnv string) []string {
	var paths []string
	if dockerConfigEnv != "" {
		paths = append(paths, path.Join(dockerConfigEnv, "config.json"))
	}
	if homeEnv != "" {
		paths = append(paths, path.Join(homeEnv, ".docker", "config.json"))
		paths = append(paths, path.Join(homeEnv, ".dockercfg"))
	}
	return paths
}