How to pull image from custom docker registry with golang?

Using docker sources how to pull image from custom registry? As a result of using such code

// Prepare auth registry for usage
func (app *App) PrepareRegistry() error {
    app.AuthConfig = types.AuthConfig{
        Username:      Username,
        Password:      Password,
        ServerAddress: DefaultServer,

    resp, err := app.Client.RegistryLogin(context.Background(), app.AuthConfig)
    if err != nil {

    if resp.IdentityToken != "" {
        app.AuthConfig.IdentityToken = resp.IdentityToken

    app.AuthConfigEncoded, err = command.EncodeAuthToBase64(app.AuthConfig)
    return err

func (app *App) ImagePull() error {

    opts := types.ImagePullOptions{
        All:            true,
        RegistryAuth: app.AuthConfigEncoded,
        PrivilegeFunc: registryAuthentication(app.Name),
    responseBody, err := app.Client.ImagePull(context.Background(), app.Name, opts)
    defer responseBody.Close()
    if err != nil {
        return err
    return nil

I am still getting the error

  • Heroku-docker not working on osx
  • Docker invalid tag value
  • How to detect if docker run succeeded programmatically?
  • Is it possible to bind multiple folders in Docker?
  • How can I start php-fpm in a Docker container by default?
  • IBM Containers: Unable to login with “cf ic login”
  • Login Succeeded
    panic: Error response from daemon: Get unauthorized: incorrect username or password

    While ServerAddress is, not

  • Jenkins in docker with access to host docker
  • Gitlab CI Runner Docker Executor Expose Ports
  • Makefile hangs when docker-compose -d is used and fails with code 129 without -d
  • Docker swarm replicas on different nodes
  • docker login not working with nexus 3 private registry
  • Mounting volumes before executing commands with docker-compose and boot2docker
  • One Solution collect form web for “How to pull image from custom docker registry with golang?”

    Did you check identity token? That might cause an authentication problem.

    A suggestion:
    Docker client

    This works fine, as I can see you did not specify the endpoint. I think you should add this info.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.