goland docker sdk. Filter tasks list with struct

  docker, go, sdk

I’m trying to write a script in golang to output filtered tasks in docker swarm.

Docker sdk golang ref – https://pkg.go.dev/github.com/docker/docker/client#Client.TaskList

Im want to filter tasks by image or id, nvm.

My unsuccessful attempt is below

package main

import (
        "context"
        "fmt"

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

func main() {
        cli, err := client.NewEnvClient()
        if err != nil {
                panic(err)
        }
        //args := types.ServiceListOptions{&filters.Args{image.name:{ubuntu:false}}}

        services, err := cli.TaskList(context.Background(), types.TaskListOptions{Filters: filters.Args{"id":{"vj7set6z8phhw31djdnytetvs":true}}})
        if err != nil{
                panic(err)
        }

        for _, serv := range services {
                fmt.Printf("%s n", serv.ID)
        }
}

Where can I find the parameters to filter?

Source: Docker Questions

LEAVE A COMMENT