use Binds key in hostConfig to detect volumes mounted from external.

This commit is contained in:
Liang-Chi Hsieh 2013-11-13 14:59:24 +08:00
parent 6a693176d6
commit 1d7f22c0d4

View file

@ -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 {