github.com/jen20/docker@v1.13.1/daemon/mounts.go (about)

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