github.com/rish1988/moby@v25.0.2+incompatible/daemon/mounts.go (about) 1 package daemon // import "github.com/docker/docker/daemon" 2 3 import ( 4 "context" 5 "fmt" 6 "strings" 7 8 "github.com/containerd/log" 9 mounttypes "github.com/docker/docker/api/types/mount" 10 "github.com/docker/docker/container" 11 volumesservice "github.com/docker/docker/volume/service" 12 ) 13 14 func (daemon *Daemon) prepareMountPoints(container *container.Container) error { 15 alive := container.IsRunning() 16 for _, config := range container.MountPoints { 17 if err := daemon.lazyInitializeVolume(container.ID, config); err != nil { 18 return err 19 } 20 if config.Volume == nil { 21 // FIXME(thaJeztah): should we check for config.Type here as well? (i.e., skip bind-mounts etc) 22 continue 23 } 24 if alive { 25 log.G(context.TODO()).WithFields(log.Fields{ 26 "container": container.ID, 27 "volume": config.Volume.Name(), 28 }).Debug("Live-restoring volume for alive container") 29 if err := config.LiveRestore(context.TODO()); err != nil { 30 return err 31 } 32 } 33 } 34 return nil 35 } 36 37 func (daemon *Daemon) removeMountPoints(container *container.Container, rm bool) error { 38 var rmErrors []string 39 ctx := context.TODO() 40 for _, m := range container.MountPoints { 41 if m.Type != mounttypes.TypeVolume || m.Volume == nil { 42 continue 43 } 44 daemon.volumes.Release(ctx, m.Volume.Name(), container.ID) 45 if !rm { 46 continue 47 } 48 49 // Do not remove named mountpoints 50 // these are mountpoints specified like `docker run -v <name>:/foo` 51 if m.Spec.Source != "" { 52 continue 53 } 54 55 err := daemon.volumes.Remove(ctx, m.Volume.Name()) 56 // Ignore volume in use errors because having this 57 // volume being referenced by other container is 58 // not an error, but an implementation detail. 59 // This prevents docker from logging "ERROR: Volume in use" 60 // where there is another container using the volume. 61 if err != nil && !volumesservice.IsInUse(err) { 62 rmErrors = append(rmErrors, err.Error()) 63 } 64 } 65 66 if len(rmErrors) > 0 { 67 return fmt.Errorf("Error removing volumes:\n%v", strings.Join(rmErrors, "\n")) 68 } 69 return nil 70 }