Can I pin docker API version : client version 1.38 is too new. Maximum supported API version is 1.37

You can ask for a version specifically with NewClientWithOpts().

package main

import (
    "net/http"

    "github.com/docker/docker/api/types/container"
    "github.com/docker/docker/client"
    "golang.org/x/net/context"
)

func main() {
    ctx := context.Background()
    cli, err := client.NewClientWithOpts(client.WithVersion("1.37"))
    if err != nil {
        panic(err)
    }
}

See Versioned API and SDK. At the tail end it brings up using the Go API and (tries) to link to the relevant code:

You can specify the API version to use, in one of the following ways:

  • ...

  • ...

  • ...

  • For the SDKs, you can also specify the API version programmatically, as a parameter to the client object. See the Go constructor or the Python SDK documentation for client.

The docs hard link to a line number on the master branch which has probably changed, but the code above should provide you with enough context to understand.


I had the exact same problem and @zero298's answer worked perfectly for me =)

Then I found client.WithAPIVersionNegotiation() and that also worked!

If you don't require pinning the version and just want the code to work with whatever version your machine is running, I think this option will suite your needs.


ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
   panic(err)
}
cli.NegotiateAPIVersion(ctx)  // this line can negotiate API version

NegotiateAPIVersion of client method can solve this API version mismatch problem.