diff --git a/daemon/mounts.go b/daemon/mounts.go index 4f3669d37ca45..81a82753ecdf7 100644 --- a/daemon/mounts.go +++ b/daemon/mounts.go @@ -10,13 +10,8 @@ import ( func (daemon *Daemon) prepareMountPoints(container *container.Container) error { for _, config := range container.MountPoints { - if len(config.Driver) > 0 { - v, err := daemon.volumes.GetWithRef(config.Name, config.Driver, container.ID) - if err != nil { - return err - } - - config.Volume = v + if err := daemon.lazyInitializeVolume(container.ID, config); err != nil { + return err } } return nil diff --git a/daemon/volumes.go b/daemon/volumes.go index a7b648a56f501..c0097679f6ab0 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -153,3 +153,17 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo return nil } + +// lazyInitializeVolume initializes a mountpoint's volume if needed. +// This happens after a daemon restart. +func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volume.MountPoint) error { + if len(m.Driver) > 0 && m.Volume == nil { + v, err := daemon.volumes.GetWithRef(m.Name, m.Driver, containerID) + + if err != nil { + return err + } + m.Volume = v + } + return nil +} diff --git a/daemon/volumes_unix.go b/daemon/volumes_unix.go index ea19953093061..f257da770c001 100644 --- a/daemon/volumes_unix.go +++ b/daemon/volumes_unix.go @@ -20,6 +20,9 @@ import ( func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) { var mounts []execdriver.Mount for _, m := range container.MountPoints { + if err := daemon.lazyInitializeVolume(container.ID, m); err != nil { + return nil, err + } path, err := m.Setup() if err != nil { return nil, err diff --git a/daemon/volumes_windows.go b/daemon/volumes_windows.go index dd4a9c9f2c05c..05a45c385dca4 100644 --- a/daemon/volumes_windows.go +++ b/daemon/volumes_windows.go @@ -18,6 +18,9 @@ import ( func (daemon *Daemon) setupMounts(container *container.Container) ([]execdriver.Mount, error) { var mnts []execdriver.Mount for _, mount := range container.MountPoints { // type is volume.MountPoint + if err := daemon.lazyInitializeVolume(container.ID, mount); err != nil { + return nil, err + } // If there is no source, take it from the volume path s := mount.Source if s == "" && mount.Volume != nil {