2c72015c |
package daemon
import ( |
a793564b |
"fmt" |
2c72015c |
"strings"
|
3cf18596 |
mounttypes "github.com/docker/docker/api/types/mount" |
6bb0d181 |
"github.com/docker/docker/container" |
43012fe8 |
volumestore "github.com/docker/docker/volume/store" |
2c72015c |
)
|
aab35963 |
func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
for _, config := range container.MountPoints {
if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
return err
}
}
return nil
}
|
6bb0d181 |
func (daemon *Daemon) removeMountPoints(container *container.Container, rm bool) error { |
2c72015c |
var rmErrors []string
for _, m := range container.MountPoints { |
3cf18596 |
if m.Type != mounttypes.TypeVolume || m.Volume == nil { |
2c72015c |
continue
} |
d3eca445 |
daemon.volumes.Dereference(m.Volume, container.ID) |
3cf18596 |
if !rm {
continue
}
// Do not remove named mountpoints
// these are mountpoints specified like `docker run -v <name>:/foo`
if m.Spec.Source != "" {
continue
}
err := daemon.volumes.Remove(m.Volume)
// Ignore volume in use errors because having this
// volume being referenced by other container is
// not an error, but an implementation detail.
// This prevents docker from logging "ERROR: Volume in use"
// where there is another container using the volume.
if err != nil && !volumestore.IsInUse(err) {
rmErrors = append(rmErrors, err.Error()) |
2c72015c |
}
} |
3cf18596 |
|
2c72015c |
if len(rmErrors) > 0 { |
a793564b |
return fmt.Errorf("Error removing volumes:\n%v", strings.Join(rmErrors, "\n")) |
2c72015c |
}
return nil
} |