title: Can I pin docker API version : client version 1.38 is too new. Maximum supported API version is 1.37
body: <p>Is there a way to pin docker API version using the golang client? (short of using <a href="https://github.com/golang/dep" rel="noreferrer">dep for vendoring</a>)</p>
  
  <p>code below fails with</p>
  
  <pre><code>client version 1.38 is too new. Maximum supported API version is 1.37
  </code></pre>
  
  <p>This code ran fine until recently</p>
  
  <pre><code>go version go1.9.5 linux/amd64
  </code></pre>
  
  <p>here is :  <code>docker version</code></p>
  
  <pre><code>Client:
   Version:      18.05.0-ce
   API version:  1.37
   Go version:   go1.9.5
   Git commit:   f150324
   Built:        Wed May  9 22:16:25 2018
   OS/Arch:      linux/amd64
   Experimental: false
   Orchestrator: swarm
  
  Server:
   Engine:
    Version:      18.05.0-ce
    API version:  1.37 (minimum version 1.12)
    Go version:   go1.9.5
    Git commit:   f150324
    Built:        Wed May  9 22:14:32 2018
    OS/Arch:      linux/amd64
    Experimental: false
  </code></pre>
  
  <p>this kicks up the API version mismatch</p>
  
  <pre><code>package main
  
  // kill off some containers
  
  import (
      "fmt"
  
      "github.com/docker/docker/api/types"
      "github.com/docker/docker/client"
      "golang.org/x/net/context"
  
      "strings"
  )
  
  func main() {
      ctx := context.Background()
      cli, err := client.NewEnvClient()
      if err != nil {
          panic(err) // &lt;--- crashes here due to API mismatch
      }
  
      containers, err := cli.ContainerList(ctx, types.ContainerListOptions{})
      if err != nil {
          panic(err)
      }
  
      for _, container := range containers {
  
          if strings.Contains(container.Image, "enduser") || strings.Contains(container.Image, "admin") {
  
              fmt.Println("\n we found enduser or admin so lets stop it\n")
  
              fmt.Print("Stopping container ", container.ID[:10], "... ")
              if err := cli.ContainerStop(ctx, container.ID, nil); err != nil {
                  panic(err)
              }
              fmt.Println("Success")
          }
      }
  }
  </code></pre>
  
  <p>In English, the above error is because the default client version of the github repo client library is newer than version supported by Docker ... so to address the comment - one approach which works is to request a lower version of the repo library to match Docker, not to request a higher version</p>
  
  <p>Below approach to negotiate also works fine </p>
  
  <blockquote>
    <p>cli, err := client.NewClientWithOpts(client.WithAPIVersionNegotiation())</p>
  </blockquote>