Skip to content

Commit

Permalink
Update docker client API version negotiation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtamm committed Mar 5, 2024
1 parent 134e7d5 commit 535ac82
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/funnel_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (f *Funnel) StartServerInDocker(containerName, imageName string, extraArgs

func (f *Funnel) findTestServerContainers() []string {
res := []string{}
containers, err := f.Docker.ContainerList(context.Background(), dockerTypes.ContainerListOptions{})
containers, err := f.Docker.ContainerList(context.Background(), container.ListOptions{})
if err != nil {
panic(err)
}
Expand Down
17 changes: 2 additions & 15 deletions util/dockerutil/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package dockerutil

import (
"context"
"errors"
"os"
"regexp"
"time"

"github.com/docker/docker/client"
Expand All @@ -24,19 +22,8 @@ func NewDockerClient() (*client.Client, error) {
if os.Getenv("DOCKER_API_VERSION") == "" {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

_, err := dclient.ServerVersion(ctx)
if err != nil {
re := regexp.MustCompile(`([0-9\.]+)`)
version := re.FindAllString(err.Error(), -1)
if version == nil {
return nil, errors.New("Can't connect docker client")
}
// Error message example:
// Error getting metadata for container: Error response from daemon: client is newer than server (client API version: 1.26, server API version: 1.24)
os.Setenv("DOCKER_API_VERSION", version[1])
return NewDockerClient()
}
dclient.NegotiateAPIVersion(ctx)
}

return dclient, nil
}

0 comments on commit 535ac82

Please sign in to comment.