Skip to content

Commit

Permalink
driver: software: docker: Negotiate client API
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed May 16, 2024
1 parent fbb1533 commit 2013351
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion agent/driver/software/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 2013351

Please sign in to comment.