Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@douglasmiranda
Created May 8, 2019 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglasmiranda/46256e7102bc3db3d90e167b4cb40d6c to your computer and use it in GitHub Desktop.
Save douglasmiranda/46256e7102bc3db3d90e167b4cb40d6c to your computer and use it in GitHub Desktop.
Docker client API version mismatch: Error response from daemon: client version 1.40 is too new. Maximum supported API version is 1.39

When building things that will interact with the client/server you can have a mismatch of API versions.

This is a common way to get started with the Docker client in Go: (this will create a new client based on your environment settings for Docker)

cli, err := client.NewClientWithOpts(client.FromEnv)

You may face an error similar to:

Error response from daemon: client version 1.40 is too new. Maximum supported API version is 1.39

One solution is to let the client discover what's the appropriated version to use:

ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv)
cli.NegotiateAPIVersion(ctx)

Full example:

package main

import (
	"context"
	"fmt"

	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
)

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

	containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
	if err != nil {
		panic(err)
	}

	for _, container := range containers {
		fmt.Printf("%s %s\n", container.ID[:10], container.Image)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment