github.com/kinvolk/docker@v1.13.1/client/container_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  // ContainersPrune requests the daemon to delete unused data
    13  func (cli *Client) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error) {
    14  	var report types.ContainersPruneReport
    15  
    16  	if err := cli.NewVersionError("1.25", "container 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, "/containers/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  }