mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #2488 from viirya/fix_container_volumes_delete
Skip the volumes mounted when deleting the volumes of container.
This commit is contained in:
commit
70f1bd3104
1 changed files with 16 additions and 1 deletions
17
server.go
17
server.go
|
@ -1346,9 +1346,24 @@ 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 {
|
||||
volumeId = strings.TrimRight(volumeId, "/layer")
|
||||
|
||||
// Skip the volumes mounted from external
|
||||
if _, exists := binds[volumeId]; exists {
|
||||
continue
|
||||
}
|
||||
|
||||
volumeId = strings.TrimSuffix(volumeId, "/layer")
|
||||
volumeId = filepath.Base(volumeId)
|
||||
volumes[volumeId] = struct{}{}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue