From 20133515279c4137c7be66acce2eb13b68058ccd Mon Sep 17 00:00:00 2001 From: ish Date: Thu, 16 May 2024 20:15:30 +0900 Subject: [PATCH] driver: software: docker: Negotiate client API --- agent/driver/software/docker.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/agent/driver/software/docker.go b/agent/driver/software/docker.go index c7adc81..dcbec01 100644 --- a/agent/driver/software/docker.go +++ b/agent/driver/software/docker.go @@ -25,11 +25,15 @@ func isRealDocker(cli *client.Client) (bool, error) { } func GetDockerContainers() ([]types.Container, error) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + cli, err := client.NewClientWithOpts(client.FromEnv) if err != nil { logger.Println(logger.DEBUG, true, "DOCKER: "+err.Error()) return []types.Container{}, err } + cli.NegotiateAPIVersion(ctx) yes, err := isRealDocker(cli) if err != nil { @@ -41,7 +45,7 @@ func GetDockerContainers() ([]types.Container, error) { return []types.Container{}, nil } - containers, err := cli.ContainerList(context.Background(), container.ListOptions{All: true}) + containers, err := cli.ContainerList(ctx, container.ListOptions{All: true}) if err != nil { logger.Println(logger.ERROR, true, "DOCKER: "+err.Error()) return []types.Container{}, err