@@ -871,6 +871,15 @@ MOUNTS:
871871 }
872872 }
873873 }
874+ if m .Type == mount .TypeImage {
875+ version , err := s .RuntimeVersion (ctx )
876+ if err != nil {
877+ return nil , nil , err
878+ }
879+ if versions .LessThan (version , "1.48" ) {
880+ return nil , nil , fmt .Errorf ("volume with type=image require Docker Engine v28 or later" )
881+ }
882+ }
874883 mounts = append (mounts , m )
875884 }
876885 return binds , mounts , nil
@@ -1125,7 +1134,7 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
11251134 }
11261135 }
11271136
1128- bind , vol , tmpfs := buildMountOptions (volume )
1137+ bind , vol , tmpfs , img := buildMountOptions (volume )
11291138
11301139 if bind != nil {
11311140 volume .Type = types .VolumeTypeBind
@@ -1140,37 +1149,35 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
11401149 BindOptions : bind ,
11411150 VolumeOptions : vol ,
11421151 TmpfsOptions : tmpfs ,
1152+ ImageOptions : img ,
11431153 }, nil
11441154}
11451155
1146- func buildMountOptions (volume types.ServiceVolumeConfig ) (* mount.BindOptions , * mount.VolumeOptions , * mount.TmpfsOptions ) {
1156+ func buildMountOptions (volume types.ServiceVolumeConfig ) (* mount.BindOptions , * mount.VolumeOptions , * mount.TmpfsOptions , * mount.ImageOptions ) {
1157+ if volume .Type != types .VolumeTypeBind && volume .Bind != nil {
1158+ logrus .Warnf ("mount of type `%s` should not define `bind` option" , volume .Type )
1159+ }
1160+ if volume .Type != types .VolumeTypeVolume && volume .Volume != nil {
1161+ logrus .Warnf ("mount of type `%s` should not define `volume` option" , volume .Type )
1162+ }
1163+ if volume .Type != types .VolumeTypeTmpfs && volume .Tmpfs != nil {
1164+ logrus .Warnf ("mount of type `%s` should not define `tmpfs` option" , volume .Type )
1165+ }
1166+ if volume .Type != types .VolumeTypeImage && volume .Image != nil {
1167+ logrus .Warnf ("mount of type `%s` should not define `image` option" , volume .Type )
1168+ }
1169+
11471170 switch volume .Type {
11481171 case "bind" :
1149- if volume .Volume != nil {
1150- logrus .Warnf ("mount of type `bind` should not define `volume` option" )
1151- }
1152- if volume .Tmpfs != nil {
1153- logrus .Warnf ("mount of type `bind` should not define `tmpfs` option" )
1154- }
1155- return buildBindOption (volume .Bind ), nil , nil
1172+ return buildBindOption (volume .Bind ), nil , nil , nil
11561173 case "volume" :
1157- if volume .Bind != nil {
1158- logrus .Warnf ("mount of type `volume` should not define `bind` option" )
1159- }
1160- if volume .Tmpfs != nil {
1161- logrus .Warnf ("mount of type `volume` should not define `tmpfs` option" )
1162- }
1163- return nil , buildVolumeOptions (volume .Volume ), nil
1174+ return nil , buildVolumeOptions (volume .Volume ), nil , nil
11641175 case "tmpfs" :
1165- if volume .Bind != nil {
1166- logrus .Warnf ("mount of type `tmpfs` should not define `bind` option" )
1167- }
1168- if volume .Volume != nil {
1169- logrus .Warnf ("mount of type `tmpfs` should not define `volume` option" )
1170- }
1171- return nil , nil , buildTmpfsOptions (volume .Tmpfs )
1176+ return nil , nil , buildTmpfsOptions (volume .Tmpfs ), nil
1177+ case "image" :
1178+ return nil , nil , nil , buildImageOptions (volume .Image )
11721179 }
1173- return nil , nil , nil
1180+ return nil , nil , nil , nil
11741181}
11751182
11761183func buildBindOption (bind * types.ServiceVolumeBind ) * mount.BindOptions {
@@ -1199,7 +1206,7 @@ func buildVolumeOptions(vol *types.ServiceVolumeVolume) *mount.VolumeOptions {
11991206 return & mount.VolumeOptions {
12001207 NoCopy : vol .NoCopy ,
12011208 Subpath : vol .Subpath ,
1202- // Labels: , // FIXME missing from model ?
1209+ Labels : vol . Labels ,
12031210 // DriverConfig: , // FIXME missing from model ?
12041211 }
12051212}
@@ -1214,6 +1221,15 @@ func buildTmpfsOptions(tmpfs *types.ServiceVolumeTmpfs) *mount.TmpfsOptions {
12141221 }
12151222}
12161223
1224+ func buildImageOptions (image * types.ServiceVolumeImage ) * mount.ImageOptions {
1225+ if image == nil {
1226+ return nil
1227+ }
1228+ return & mount.ImageOptions {
1229+ Subpath : image .SubPath ,
1230+ }
1231+ }
1232+
12171233func (s * composeService ) ensureNetwork (ctx context.Context , project * types.Project , name string , n * types.NetworkConfig ) (string , error ) {
12181234 if n .External {
12191235 return s .resolveExternalNetwork (ctx , n )
0 commit comments