1

I have a project that needs to manage containers through docker sdk, and I use WithAPIVersionNegotiation to reduce the version.

The example is as follows

cli, err := client.NewClientWithOpts(client.WithAPIVersionNegotiation())
    ctx := context.Background()
    if err != nil {
        panic(err)
    }
    defer cli.Close()

    cmdStatementExecuteScript := cmdStatement
    optionsCreateExecuteScript := types.ExecConfig{
        AttachStdout: true,
        AttachStderr: true,
        Cmd:          cmdStatementExecuteScript,
    }

    response, err := cli.ContainerExecCreate(ctx, containerID, optionsCreateExecuteScript)
    if err != nil {
        panic(err)
    }

But when I deploy the service on multiple machines, the following error occurs because of the different docker versions on each machine.

panic: Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.22)

WithAPIVersionNegotiation config doesn't seem to be downgraded to the required version.

Is there some way to satisfy adaptive all versions by coding? Looking forward to your reply.

PS: Use WithAPIVersionNegotiation to take effect when Error response from daemon: client version 1.42 is too new. Maximum supported API version is 1.39 appears.

go.mod:

    github.com/docker/distribution v2.8.1+incompatible // indirect
    github.com/docker/docker v23.0.4+incompatible
    github.com/docker/go-connections v0.4.0 // indirect
    github.com/docker/go-units v0.5.0 // indirect
moluzhui
  • 1,003
  • 14
  • 34

0 Answers0