From 6a693176d6b2dbf4afd36ebda2aeb9495fdf42bc Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Thu, 31 Oct 2013 23:49:30 +0800 Subject: [PATCH 1/2] skip the volumes mounted when deleting the volumes of container. --- server.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 6a5d0a3294..d790787d6c 100644 --- a/server.go +++ b/server.go @@ -1104,8 +1104,12 @@ func (srv *Server) ContainerDestroy(name string, removeVolume, removeLink bool) volumes := make(map[string]struct{}) // Store all the deleted containers volumes for _, volumeId := range container.Volumes { - volumeId = strings.TrimRight(volumeId, "/layer") - volumeId = filepath.Base(volumeId) + trim_volumeId := strings.TrimSuffix(volumeId, "/layer") + // Skip the volumes mounted + if trim_volumeId == volumeId { + continue + } + volumeId = filepath.Base(trim_volumeId) volumes[volumeId] = struct{}{} } if err := srv.runtime.Destroy(container); err != nil { From 1d7f22c0d4bb55cf797b303cc46b1944509e4085 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Wed, 13 Nov 2013 14:59:24 +0800 Subject: [PATCH 2/2] use Binds key in hostConfig to detect volumes mounted from external. --- server.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) 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 {