2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-22 21:04:34 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-09-22 21:04:34 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2016-11-17 05:46:37 +00:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2016-09-22 21:04:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ContainersPrune requests the daemon to delete unused data
|
2016-11-17 05:46:37 +00:00
|
|
|
func (cli *Client) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error) {
|
2016-09-22 21:04:34 +00:00
|
|
|
var report types.ContainersPruneReport
|
|
|
|
|
2023-09-12 12:08:54 +00:00
|
|
|
if err := cli.NewVersionError(ctx, "1.25", "container prune"); err != nil {
|
2016-11-03 00:43:32 +00:00
|
|
|
return report, err
|
|
|
|
}
|
|
|
|
|
2016-11-17 05:46:37 +00:00
|
|
|
query, err := getFiltersQuery(pruneFilters)
|
|
|
|
if err != nil {
|
|
|
|
return report, err
|
|
|
|
}
|
|
|
|
|
|
|
|
serverResp, err := cli.post(ctx, "/containers/prune", query, nil, nil)
|
2019-02-11 12:26:12 +00:00
|
|
|
defer ensureReaderClosed(serverResp)
|
2016-09-22 21:04:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return report, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil {
|
|
|
|
return report, fmt.Errorf("Error retrieving disk usage: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return report, nil
|
|
|
|
}
|