@@ -713,11 +713,13 @@ func (s *composeService) buildContainerVolumes(ctx context.Context, p types.Proj
713713MOUNTS:
714714 for _ , m := range mountOptions {
715715 volumeMounts [m .Target ] = struct {}{}
716- // `Bind` API is used when host path need to be created if missing, `Mount` is preferred otherwise
717716 if m .Type == mount .TypeBind || m .Type == mount .TypeNamedPipe {
717+ // `Mount` is preferred but does not offer option to created host path if missing
718+ // so `Bind` API is used here with raw volume string
719+ // see https://github.com/moby/moby/issues/43483
718720 for _ , v := range service .Volumes {
719721 if v .Target == m .Target && v .Bind != nil && v .Bind .CreateHostPath {
720- binds = append (binds , fmt . Sprintf ( "%s:%s:%s" , m . Source , m . Target , getBindMode ( v . Bind , m . ReadOnly ) ))
722+ binds = append (binds , v . String ( ))
721723 continue MOUNTS
722724 }
723725 }
@@ -727,23 +729,6 @@ MOUNTS:
727729 return volumeMounts , binds , mounts , nil
728730}
729731
730- func getBindMode (bind * types.ServiceVolumeBind , readOnly bool ) string {
731- mode := "rw"
732-
733- if readOnly {
734- mode = "ro"
735- }
736-
737- switch bind .SELinux {
738- case types .SELinuxShared :
739- mode += ",z"
740- case types .SELinuxPrivate :
741- mode += ",Z"
742- }
743-
744- return mode
745- }
746-
747732func buildContainerMountOptions (p types.Project , s types.ServiceConfig , img moby.ImageInspect , inherit * moby.Container ) ([]mount.Mount , error ) {
748733 var mounts = map [string ]mount.Mount {}
749734 if inherit != nil {
0 commit comments