mirror of https://github.com/docker/cli.git
Don't prune volumes on `docker system prune`
Volumes tend to carry important data and pruning them on `docker system prune` can easily cause unwanted data loss. Let's play it safe and not prune volumes on `system prune` by default, and instead provide an option. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
883d28cfce
commit
37fd6128dc
|
@ -14,6 +14,7 @@ import (
|
||||||
type pruneOptions struct {
|
type pruneOptions struct {
|
||||||
force bool
|
force bool
|
||||||
all bool
|
all bool
|
||||||
|
pruneVolumes bool
|
||||||
filter opts.FilterOpt
|
filter opts.FilterOpt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
|
flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
|
||||||
flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images not just dangling ones")
|
flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images not just dangling ones")
|
||||||
|
flags.BoolVar(&options.pruneVolumes, "volumes", false, "Prune volumes")
|
||||||
flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'label=<key>=<value>')")
|
flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'label=<key>=<value>')")
|
||||||
// "filter" flag is available in 1.28 (docker 17.04) and up
|
// "filter" flag is available in 1.28 (docker 17.04) and up
|
||||||
flags.SetAnnotation("filter", "version", []string{"1.28"})
|
flags.SetAnnotation("filter", "version", []string{"1.28"})
|
||||||
|
@ -67,12 +69,15 @@ func runPrune(dockerCli command.Cli, options pruneOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var spaceReclaimed uint64
|
var spaceReclaimed uint64
|
||||||
|
pruneFuncs := []func(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error){
|
||||||
for _, pruneFn := range []func(dockerCli command.Cli, filter opts.FilterOpt) (uint64, string, error){
|
|
||||||
prune.RunContainerPrune,
|
prune.RunContainerPrune,
|
||||||
prune.RunVolumePrune,
|
|
||||||
prune.RunNetworkPrune,
|
prune.RunNetworkPrune,
|
||||||
} {
|
}
|
||||||
|
if options.pruneVolumes {
|
||||||
|
pruneFuncs = append(pruneFuncs, prune.RunVolumePrune)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pruneFn := range pruneFuncs {
|
||||||
spc, output, err := pruneFn(dockerCli, options.filter)
|
spc, output, err := pruneFn(dockerCli, options.filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue