diff --git a/container.go b/container.go index e9fb4890b7..461004767d 100644 --- a/container.go +++ b/container.go @@ -1181,6 +1181,15 @@ func (container *Container) EnsureMounted() error { return container.Mount() } +func (container *Container) EnsureUnmounted() error { + if mounted, err := container.Mounted(); err != nil { + return err + } else if !mounted { + return nil + } + return container.Unmount() +} + func (container *Container) Mount() error { image, err := container.GetImage() if err != nil { diff --git a/runtime_test.go b/runtime_test.go index ccdf4d9563..684ca005cd 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -44,6 +44,10 @@ func nuke(runtime *Runtime) error { }(container) } wg.Wait() + + for _, container := range runtime.List() { + container.EnsureUnmounted() + } return os.RemoveAll(runtime.root) }