github.com/moby/docker@v26.1.3+incompatible/client/container_prune.go (about)

     1  package client // import "github.com/docker/docker/client"
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"fmt"
     7  
     8  	"github.com/docker/docker/api/types"
     9  	"github.com/docker/docker/api/types/filters"
    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(ctx, "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  	defer ensureReaderClosed(serverResp)
    27  	if err != nil {
    28  		return report, err
    29  	}
    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  }