@@ -801,7 +801,7 @@ func (s *composeService) buildContainerVolumes(
801801 return nil , nil , err
802802 }
803803
804- mountOptions , err := buildContainerMountOptions (p , service , imgInspect , inherit )
804+ mountOptions , err := s . buildContainerMountOptions (ctx , p , service , imgInspect , inherit )
805805 if err != nil {
806806 return nil , nil , err
807807 }
@@ -834,7 +834,7 @@ MOUNTS:
834834 return binds , mounts , nil
835835}
836836
837- func buildContainerMountOptions (p types.Project , s types.ServiceConfig , img moby.ImageInspect , inherit * moby.Container ) ([]mount.Mount , error ) {
837+ func ( s * composeService ) buildContainerMountOptions (ctx context. Context , p types.Project , service types.ServiceConfig , img moby.ImageInspect , inherit * moby.Container ) ([]mount.Mount , error ) {
838838 var mounts = map [string ]mount.Mount {}
839839 if inherit != nil {
840840 for _ , m := range inherit .Mounts {
@@ -859,7 +859,7 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
859859 }
860860 }
861861 volumes := []types.ServiceVolumeConfig {}
862- for _ , v := range s .Volumes {
862+ for _ , v := range service .Volumes {
863863 if v .Target != m .Destination || v .Source != "" {
864864 volumes = append (volumes , v )
865865 continue
@@ -872,11 +872,11 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
872872 ReadOnly : ! m .RW ,
873873 }
874874 }
875- s .Volumes = volumes
875+ service .Volumes = volumes
876876 }
877877 }
878878
879- mounts , err := fillBindMounts (p , s , mounts )
879+ mounts , err := s . fillBindMounts (ctx , p , service , mounts )
880880 if err != nil {
881881 return nil , err
882882 }
@@ -888,27 +888,27 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
888888 return values , nil
889889}
890890
891- func fillBindMounts (p types.Project , s types.ServiceConfig , m map [string ]mount.Mount ) (map [string ]mount.Mount , error ) {
892- for _ , v := range s .Volumes {
893- bindMount , err := buildMount (p , v )
891+ func ( s * composeService ) fillBindMounts (ctx context. Context , p types.Project , service types.ServiceConfig , m map [string ]mount.Mount ) (map [string ]mount.Mount , error ) {
892+ for _ , v := range service .Volumes {
893+ bindMount , err := s . buildMount (ctx , p , v )
894894 if err != nil {
895895 return nil , err
896896 }
897897 m [bindMount .Target ] = bindMount
898898 }
899899
900- secrets , err := buildContainerSecretMounts (p , s )
900+ secrets , err := s . buildContainerSecretMounts (ctx , p , service )
901901 if err != nil {
902902 return nil , err
903903 }
904- for _ , s := range secrets {
905- if _ , found := m [s .Target ]; found {
904+ for _ , secret := range secrets {
905+ if _ , found := m [secret .Target ]; found {
906906 continue
907907 }
908- m [s .Target ] = s
908+ m [secret .Target ] = secret
909909 }
910910
911- configs , err := buildContainerConfigMounts (p , s )
911+ configs , err := s . buildContainerConfigMounts (ctx , p , service )
912912 if err != nil {
913913 return nil , err
914914 }
@@ -921,11 +921,11 @@ func fillBindMounts(p types.Project, s types.ServiceConfig, m map[string]mount.M
921921 return m , nil
922922}
923923
924- func buildContainerConfigMounts (p types.Project , s types.ServiceConfig ) ([]mount.Mount , error ) {
924+ func ( s * composeService ) buildContainerConfigMounts (ctx context. Context , p types.Project , service types.ServiceConfig ) ([]mount.Mount , error ) {
925925 var mounts = map [string ]mount.Mount {}
926926
927927 configsBaseDir := "/"
928- for _ , config := range s .Configs {
928+ for _ , config := range service .Configs {
929929 target := config .Target
930930 if config .Target == "" {
931931 target = configsBaseDir + config .Source
@@ -953,7 +953,7 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount
953953 continue
954954 }
955955
956- bindMount , err := buildMount (p , types.ServiceVolumeConfig {
956+ bindMount , err := s . buildMount (ctx , p , types.ServiceVolumeConfig {
957957 Type : types .VolumeTypeBind ,
958958 Source : definedConfig .File ,
959959 Target : target ,
@@ -971,11 +971,11 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount
971971 return values , nil
972972}
973973
974- func buildContainerSecretMounts (p types.Project , s types.ServiceConfig ) ([]mount.Mount , error ) {
974+ func ( s * composeService ) buildContainerSecretMounts (ctx context. Context , p types.Project , service types.ServiceConfig ) ([]mount.Mount , error ) {
975975 var mounts = map [string ]mount.Mount {}
976976
977977 secretsDir := "/run/secrets/"
978- for _ , secret := range s .Secrets {
978+ for _ , secret := range service .Secrets {
979979 target := secret .Target
980980 if secret .Target == "" {
981981 target = secretsDir + secret .Source
@@ -1003,7 +1003,7 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount
10031003 continue
10041004 }
10051005
1006- mnt , err := buildMount (p , types.ServiceVolumeConfig {
1006+ mnt , err := s . buildMount (ctx , p , types.ServiceVolumeConfig {
10071007 Type : types .VolumeTypeBind ,
10081008 Source : definedSecret .File ,
10091009 Target : target ,
@@ -1039,7 +1039,7 @@ func isWindowsAbs(p string) bool {
10391039 return false
10401040}
10411041
1042- func buildMount (project types.Project , volume types.ServiceVolumeConfig ) (mount.Mount , error ) {
1042+ func ( s * composeService ) buildMount (ctx context. Context , project types.Project , volume types.ServiceVolumeConfig ) (mount.Mount , error ) {
10431043 source := volume .Source
10441044 // on windows, filepath.IsAbs(source) is false for unix style abs path like /var/run/docker.sock.
10451045 // do not replace these with filepath.Abs(source) that will include a default drive.
@@ -1060,7 +1060,10 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
10601060 }
10611061 }
10621062
1063- bind , vol , tmpfs := buildMountOptions (volume )
1063+ bind , vol , tmpfs , err := s .buildMountOptions (ctx , volume )
1064+ if err != nil {
1065+ return mount.Mount {}, err
1066+ }
10641067
10651068 volume .Target = path .Clean (volume .Target )
10661069
@@ -1080,7 +1083,7 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
10801083 }, nil
10811084}
10821085
1083- func buildMountOptions (volume types.ServiceVolumeConfig ) (* mount.BindOptions , * mount.VolumeOptions , * mount.TmpfsOptions ) {
1086+ func ( s * composeService ) buildMountOptions (ctx context. Context , volume types.ServiceVolumeConfig ) (* mount.BindOptions , * mount.VolumeOptions , * mount.TmpfsOptions , error ) {
10841087 switch volume .Type {
10851088 case "bind" :
10861089 if volume .Volume != nil {
@@ -1089,43 +1092,47 @@ func buildMountOptions(volume types.ServiceVolumeConfig) (*mount.BindOptions, *m
10891092 if volume .Tmpfs != nil {
10901093 logrus .Warnf ("mount of type `bind` should not define `tmpfs` option" )
10911094 }
1092- return buildBindOption (volume .Bind ), nil , nil
1095+ option , err := s .buildBindOption (ctx , volume .Bind )
1096+ return option , nil , nil , err
10931097 case "volume" :
10941098 if volume .Bind != nil {
10951099 logrus .Warnf ("mount of type `volume` should not define `bind` option" )
10961100 }
10971101 if volume .Tmpfs != nil {
10981102 logrus .Warnf ("mount of type `volume` should not define `tmpfs` option" )
10991103 }
1100- return nil , buildVolumeOptions (volume .Volume ), nil
1104+ return nil , buildVolumeOptions (volume .Volume ), nil , nil
11011105 case "tmpfs" :
11021106 if volume .Bind != nil {
11031107 logrus .Warnf ("mount of type `tmpfs` should not define `bind` option" )
11041108 }
11051109 if volume .Volume != nil {
11061110 logrus .Warnf ("mount of type `tmpfs` should not define `volume` option" )
11071111 }
1108- return nil , nil , buildTmpfsOptions (volume .Tmpfs )
1112+ return nil , nil , buildTmpfsOptions (volume .Tmpfs ), nil
11091113 }
1110- return nil , nil , nil
1114+ return nil , nil , nil , nil
11111115}
11121116
1113- func buildBindOption (bind * types.ServiceVolumeBind ) * mount.BindOptions {
1117+ func ( s * composeService ) buildBindOption (ctx context. Context , bind * types.ServiceVolumeBind ) ( * mount.BindOptions , error ) {
11141118 if bind == nil {
1115- return nil
1119+ return nil , nil
11161120 }
11171121
1118- // I miss ternary operator
1119- propagation := types .PropagationRPrivate
1120- if bind .Propagation != "" {
1121- propagation = bind .Propagation
1122+ propagation := bind .Propagation
1123+ isWindowsContainer , err := s .isWindowsContainer (ctx )
1124+ if err != nil {
1125+ return nil , err
1126+ }
1127+ if propagation == "" && ! isWindowsContainer {
1128+ propagation = types .PropagationRPrivate
11221129 }
11231130
11241131 return & mount.BindOptions {
11251132 Propagation : mount .Propagation (propagation ),
11261133 CreateMountpoint : bind .CreateHostPath ,
11271134 // NonRecursive: false, FIXME missing from model ?
1128- }
1135+ }, nil
11291136}
11301137
11311138func buildVolumeOptions (vol * types.ServiceVolumeVolume ) * mount.VolumeOptions {
0 commit comments