github.com/MaximeAubanel/moby@v1.13.1/client/image_prune.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/filters"
     9  	"golang.org/x/net/context"
    10  )
    11  
    12  // ImagesPrune requests the daemon to delete unused data
    13  func (cli *Client) ImagesPrune(ctx context.Context, pruneFilters filters.Args) (types.ImagesPruneReport, error) {
    14  	var report types.ImagesPruneReport
    15  
    16  	if err := cli.NewVersionError("1.25", "image prune"); err != nil {
    17  		return report, err
    18  	}
    19  
    20  	query, err := getFiltersQuery(pruneFilters)
    21  	if err != nil {
    22  		return report, err
    23  	}
    24  
    25  	serverResp, err := cli.post(ctx, "/images/prune", query, nil, nil)
    26  	if err != nil {
    27  		return report, err
    28  	}
    29  	defer ensureReaderClosed(serverResp)
    30  
    31  	if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil {
    32  		return report, fmt.Errorf("Error retrieving disk usage: %v", err)
    33  	}
    34  
    35  	return report, nil
    36  }