github.com/skanehira/moby@v17.12.1-ce-rc2+incompatible/daemon/mounts.go (about)

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