github.com/kinvolk/docker@v1.13.1/client/image_list.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/url"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/filters"
     9  	"github.com/docker/docker/api/types/versions"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  // ImageList returns a list of images in the docker host.
    14  func (cli *Client) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) {
    15  	var images []types.ImageSummary
    16  	query := url.Values{}
    17  
    18  	optionFilters := options.Filters
    19  	referenceFilters := optionFilters.Get("reference")
    20  	if versions.LessThan(cli.version, "1.25") && len(referenceFilters) > 0 {
    21  		query.Set("filter", referenceFilters[0])
    22  		for _, filterValue := range referenceFilters {
    23  			optionFilters.Del("reference", filterValue)
    24  		}
    25  	}
    26  	if optionFilters.Len() > 0 {
    27  		filterJSON, err := filters.ToParamWithVersion(cli.version, optionFilters)
    28  		if err != nil {
    29  			return images, err
    30  		}
    31  		query.Set("filters", filterJSON)
    32  	}
    33  	if options.All {
    34  		query.Set("all", "1")
    35  	}
    36  
    37  	serverResp, err := cli.get(ctx, "/images/json", query, nil)
    38  	if err != nil {
    39  		return images, err
    40  	}
    41  
    42  	err = json.NewDecoder(serverResp.body).Decode(&images)
    43  	ensureReaderClosed(serverResp)
    44  	return images, err
    45  }