mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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")
|
return fmt.Errorf("Impossible to remove a running container, please stop it first")
|
||||||
}
|
}
|
||||||
volumes := make(map[string]struct{})
|
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
|
// Store all the deleted containers volumes
|
||||||
for _, volumeId := range container.Volumes {
|
for _, volumeId := range container.Volumes {
|
||||||
trim_volumeId := strings.TrimSuffix(volumeId, "/layer")
|
|
||||||
// Skip the volumes mounted
|
// Skip the volumes mounted from external
|
||||||
if trim_volumeId == volumeId {
|
if _, exists := binds[volumeId]; exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
volumeId = filepath.Base(trim_volumeId)
|
|
||||||
|
volumeId = strings.TrimSuffix(volumeId, "/layer")
|
||||||
|
volumeId = filepath.Base(volumeId)
|
||||||
volumes[volumeId] = struct{}{}
|
volumes[volumeId] = struct{}{}
|
||||||
}
|
}
|
||||||
if err := srv.runtime.Destroy(container); err != nil {
|
if err := srv.runtime.Destroy(container); err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue