mounts.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package daemon
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/docker/docker/container"
  6. volumestore "github.com/docker/docker/volume/store"
  7. )
  8. func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
  9. for _, config := range container.MountPoints {
  10. if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
  11. return err
  12. }
  13. }
  14. return nil
  15. }
  16. func (daemon *Daemon) removeMountPoints(container *container.Container, rm bool) error {
  17. var rmErrors []string
  18. for _, m := range container.MountPoints {
  19. if m.Volume == nil {
  20. continue
  21. }
  22. daemon.volumes.Dereference(m.Volume, container.ID)
  23. if rm {
  24. // Do not remove named mountpoints
  25. // these are mountpoints specified like `docker run -v <name>:/foo`
  26. if m.Named {
  27. continue
  28. }
  29. err := daemon.volumes.Remove(m.Volume)
  30. // Ignore volume in use errors because having this
  31. // volume being referenced by other container is
  32. // not an error, but an implementation detail.
  33. // This prevents docker from logging "ERROR: Volume in use"
  34. // where there is another container using the volume.
  35. if err != nil && !volumestore.IsInUse(err) {
  36. rmErrors = append(rmErrors, err.Error())
  37. }
  38. }
  39. }
  40. if len(rmErrors) > 0 {
  41. return fmt.Errorf("Error removing volumes:\n%v", strings.Join(rmErrors, "\n"))
  42. }
  43. return nil
  44. }