func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { pruneFilters := opts.filter.Value() pruneFilters.Add("dangling", fmt.Sprintf("%v", !opts.all)) warning := danglingWarning if opts.all { warning = allImageWarning } if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { return } report, err := dockerCli.Client().ImagesPrune(context.Background(), pruneFilters) if err != nil { return } if len(report.ImagesDeleted) > 0 { output = "Deleted Images:\n" for _, st := range report.ImagesDeleted { if st.Untagged != "" { output += fmt.Sprintln("untagged:", st.Untagged) } else { output += fmt.Sprintln("deleted:", st.Deleted) } } spaceReclaimed = report.SpaceReclaimed } return }
func runPrune(dockerCli *command.DockerCli, opts pruneOptions) error { var message string if opts.all { message = fmt.Sprintf(warning, allImageDesc) } else { message = fmt.Sprintf(warning, danglingImageDesc) } if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), message) { return nil } var spaceReclaimed uint64 for _, pruneFn := range []func(dockerCli *command.DockerCli) (uint64, string, error){ prune.RunContainerPrune, prune.RunVolumePrune, prune.RunNetworkPrune, } { spc, output, err := pruneFn(dockerCli) if err != nil { return err } spaceReclaimed += spc if output != "" { fmt.Fprintln(dockerCli.Out(), output) } } spc, output, err := prune.RunImagePrune(dockerCli, opts.all) if err != nil { return err } if spc > 0 { spaceReclaimed += spc fmt.Fprintln(dockerCli.Out(), output) } fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) return nil }
func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (output string, err error) { if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { return } report, err := dockerCli.Client().NetworksPrune(context.Background(), types.NetworksPruneConfig{}) if err != nil { return } if len(report.NetworksDeleted) > 0 { output = "Deleted Networks:\n" for _, id := range report.NetworksDeleted { output += id + "\n" } } return }
func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { return } report, err := dockerCli.Client().VolumesPrune(context.Background(), types.VolumesPruneConfig{}) if err != nil { return } if len(report.VolumesDeleted) > 0 { output = "Deleted Volumes:\n" for _, id := range report.VolumesDeleted { output += id + "\n" } spaceReclaimed = report.SpaceReclaimed } return }
func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { pruneFilters := opts.filter.Value() if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { return } report, err := dockerCli.Client().ContainersPrune(context.Background(), pruneFilters) if err != nil { return } if len(report.ContainersDeleted) > 0 { output = "Deleted Containers:\n" for _, id := range report.ContainersDeleted { output += id + "\n" } spaceReclaimed = report.SpaceReclaimed } return }