diff --git a/daemon/delete.go b/daemon/delete.go index 99b515d014..e11d35e9a4 100644 --- a/daemon/delete.go +++ b/daemon/delete.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/container" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/system" + "github.com/docker/docker/volume" volumestore "github.com/docker/docker/volume/store" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -148,10 +149,19 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo // If the volume is referenced by a container it is not removed // This is called directly from the Engine API func (daemon *Daemon) VolumeRm(name string, force bool) error { - err := daemon.volumeRm(name) + v, err := daemon.volumes.Get(name) + if err != nil { + if force && volumestore.IsNotExist(err) { + return nil + } + return err + } + + err = daemon.volumeRm(v) if err != nil && volumestore.IsInUse(err) { return stateConflictError{err} } + if err == nil || force { daemon.volumes.Purge(name) return nil @@ -159,12 +169,7 @@ func (daemon *Daemon) VolumeRm(name string, force bool) error { return err } -func (daemon *Daemon) volumeRm(name string) error { - v, err := daemon.volumes.Get(name) - if err != nil { - return err - } - +func (daemon *Daemon) volumeRm(v volume.Volume) error { if err := daemon.volumes.Remove(v); err != nil { return errors.Wrap(err, "unable to remove volume") } diff --git a/daemon/prune.go b/daemon/prune.go index 66eca2b6e5..cf725d79be 100644 --- a/daemon/prune.go +++ b/daemon/prune.go @@ -140,7 +140,7 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg if err != nil { logrus.Warnf("could not determine size of volume %s: %v", name, err) } - err = daemon.volumes.Remove(v) + err = daemon.volumeRm(v) if err != nil { logrus.Warnf("could not remove volume %s: %v", name, err) return nil