@@ -1452,6 +1452,39 @@ func (mgr *ContainerManager) parseBinds(ctx context.Context, meta *ContainerMeta
14521452 }
14531453 }()
14541454
1455+ // parse volumes from image
1456+ image , err := mgr .ImageMgr .GetImage (ctx , meta .Image )
1457+ if err != nil {
1458+ return errors .Wrapf (err , "failed to get image: %s" , meta .Image )
1459+ }
1460+ for dest := range image .Config .Volumes {
1461+ name := randomid .Generate ()
1462+ if _ , exist := meta .Config .Volumes [name ]; exist {
1463+ continue
1464+ }
1465+
1466+ mp := new (types.MountPoint )
1467+ mp .Name = name
1468+ mp .Named = true
1469+ mp .Destination = dest
1470+
1471+ mp .Source , mp .Driver , err = mgr .bindVolume (ctx , mp .Name , meta )
1472+ if err != nil {
1473+ logrus .Errorf ("failed to bind volume: %s, err: %v" , mp .Name , err )
1474+ return errors .Wrap (err , "failed to bind volume" )
1475+ }
1476+
1477+ err = opts .ParseBindMode (mp , "" )
1478+ if err != nil {
1479+ logrus .Errorf ("failed to parse mode, err: %v" , err )
1480+ return err
1481+ }
1482+
1483+ meta .Config .Volumes [mp .Name ] = mp .Destination
1484+ meta .Mounts = append (meta .Mounts , mp )
1485+ }
1486+
1487+ // parse volumes from other containers
14551488 for _ , v := range meta .HostConfig .VolumesFrom {
14561489 var containerID , mode string
14571490 containerID , mode , err = opts .ParseVolumesFrom (v )
@@ -1631,12 +1664,27 @@ func (mgr *ContainerManager) setMountPointDiskQuota(ctx context.Context, c *Cont
16311664
16321665 for _ , mp := range c .Mounts {
16331666 // skip volume mount or replace mode mount
1634- if mp .Name != "" || mp .Replace != "" || mp .Source == "" || mp .Destination == "" {
1667+ if mp .Replace != "" || mp .Source == "" || mp .Destination == "" {
1668+ logrus .Debugf ("skip volume mount or replace mode mount" )
16351669 continue
16361670 }
16371671
1672+ if mp .Name != "" {
1673+ v , err := mgr .VolumeMgr .Get (ctx , mp .Name )
1674+ if err != nil {
1675+ logrus .Warnf ("failed to get volume: %s" , mp .Name )
1676+ continue
1677+ }
1678+
1679+ if v .Size () != "" {
1680+ logrus .Debugf ("skip volume: %s with size" , mp .Name )
1681+ continue
1682+ }
1683+ }
1684+
16381685 // skip non-directory path.
16391686 if fd , err := os .Stat (mp .Source ); err != nil || ! fd .IsDir () {
1687+ logrus .Debugf ("skip non-directory path: %s" , mp .Source )
16401688 continue
16411689 }
16421690
0 commit comments