diff --git a/server.go b/server.go index d790787d6c..b7f16fe9a4 100644 --- a/server.go +++ b/server.go @@ -1102,14 +1102,25 @@ func (srv *Server) ContainerDestroy(name string, removeVolume, removeLink bool) return fmt.Errorf("Impossible to remove a running container, please stop it first") } volumes := make(map[string]struct{}) + + binds := make(map[string]struct{}) + + for _, bind := range container.hostConfig.Binds { + splitBind := strings.Split(bind, ":") + source := splitBind[0] + binds[source] = struct{}{} + } + // Store all the deleted containers volumes for _, volumeId := range container.Volumes { - trim_volumeId := strings.TrimSuffix(volumeId, "/layer") - // Skip the volumes mounted - if trim_volumeId == volumeId { - continue - } - volumeId = filepath.Base(trim_volumeId) + + // Skip the volumes mounted from external + if _, exists := binds[volumeId]; exists { + continue + } + + volumeId = strings.TrimSuffix(volumeId, "/layer") + volumeId = filepath.Base(volumeId) volumes[volumeId] = struct{}{} } if err := srv.runtime.Destroy(container); err != nil {