@@ -424,18 +424,6 @@ func (c *Container) init(allowCreate bool) error {
424424
425425 c .status .CreatedAt , _ = time .Parse (time .RFC3339Nano , cjson .Created )
426426
427- contConfig , err := c .containerConfig (cjson )
428- if err != nil {
429- c .Log (ERROR , err )
430- return err
431- }
432- c .contConfig = contConfig
433-
434- if err != nil {
435- c .Log (ERROR , err )
436- return err
437- }
438-
439427 c .mergeVolumes (cjson )
440428
441429 if ! loaded {
@@ -451,6 +439,13 @@ func (c *Container) init(allowCreate bool) error {
451439 c .injectFiles (c .mountId )
452440 }
453441
442+ contConfig , err := c .containerConfig (cjson )
443+ if err != nil {
444+ c .Log (ERROR , err )
445+ return err
446+ }
447+ c .contConfig = contConfig
448+
454449 return nil
455450}
456451
@@ -559,26 +554,54 @@ func (c *Container) cmdEnvs(envs []vc.EnvVar) []vc.EnvVar {
559554 return envs
560555}
561556
562- func newMount (m dockertypes.MountPoint ) vc.Mount {
557+ func newcMount (m dockertypes.MountPoint ) vc.Mount {
563558 return vc.Mount {
564559 Source : m .Source ,
565560 Destination : m .Destination ,
566561 }
567562}
568563
569- func containerMounts (cjson * dockertypes.ContainerJSON ) []vc.Mount {
564+ func newOciMount (m dockertypes.MountPoint ) specs.Mount {
565+ return specs.Mount {
566+ Source : m .Source ,
567+ Destination : m .Destination ,
568+ }
569+ }
570+
571+ func (c * Container ) containerOciMounts (cjson * dockertypes.ContainerJSON ) ([]vc.Mount , []specs.Mount ) {
570572 cMounts := cjson .Mounts
571573
572- if cMounts == nil {
573- return []vc.Mount {}
574- }
574+ var cmnts []vc.Mount
575+ var ocimnts []specs.Mount
575576
576- var mnts []vc.Mount
577577 for _ , m := range cMounts {
578- mnts = append (mnts , newMount (m ))
578+ cmnts = append (cmnts , newcMount (m ))
579+ ocimnts = append (ocimnts , newOciMount (m ))
580+ }
581+
582+ for _ , vol := range c .spec .Volumes {
583+ if vol .Detail .Format == "vfs" {
584+ cmnt := vc.Mount {
585+ Source : vol .Detail .Source ,
586+ Destination : vol .Path ,
587+ Type : "bind" ,
588+ ReadOnly : vol .ReadOnly ,
589+ }
590+
591+ cmnts = append (cmnts , cmnt )
592+
593+ ocimnt := specs.Mount {
594+ Source : vol .Detail .Source ,
595+ Destination : vol .Path ,
596+ Type : "bind" ,
597+ Options : []string {"rbind" , "rprivate" },
598+ }
599+
600+ ocimnts = append (ocimnts , ocimnt )
601+ }
579602 }
580603
581- return mnts
604+ return cmnts , ocimnts
582605}
583606
584607func (c * Container ) ociEnv () []string {
@@ -660,6 +683,11 @@ func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.Conta
660683 oci .RemoveNamespace (ociSpec , ns )
661684 }
662685
686+ cmnts , ocimnts := c .containerOciMounts (cjson )
687+ for _ , mnt := range ocimnts {
688+ ociSpec .Mounts = append (ociSpec .Mounts , mnt )
689+ }
690+
663691 ociSpecJson , err := json .Marshal (ociSpec )
664692 if err != nil {
665693 return & vc.ContainerConfig {}, nil
@@ -704,7 +732,7 @@ func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.Conta
704732 vcAnnotations .ConfigJSONKey : string (ociSpecJson ),
705733 vcAnnotations .BundlePathKey : path .Join (c .p .sandboxShareDir (), mountId ),
706734 },
707- Mounts : containerMounts ( cjson ) ,
735+ Mounts : cmnts ,
708736 }
709737
710738 c .Log (TRACE , "Container Info is \n %#v" , containerConfig )
0 commit comments