mounts.go 1.4 KB

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