use Binds key in hostConfig to detect volumes mounted from external.
This commit is contained in:
parent
6a693176d6
commit
1d7f22c0d4
1 changed files with 17 additions and 6 deletions
23
server.go
23
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 {
|
||||
|
|
Loading…
Reference in a new issue