Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 28ef6cc

Browse files
authored
Merge pull request #1531 from docker/mount_options
ignore mount options which don't match type
2 parents 74773b9 + 6ec682c commit 28ef6cc

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

local/compose/create.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,18 +774,50 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
774774
}
775775
}
776776

777+
bind, vol, tmpfs := buildMountOptions(volume)
778+
777779
return mount.Mount{
778780
Type: mount.Type(volume.Type),
779781
Source: source,
780782
Target: volume.Target,
781783
ReadOnly: volume.ReadOnly,
782784
Consistency: mount.Consistency(volume.Consistency),
783-
BindOptions: buildBindOption(volume.Bind),
784-
VolumeOptions: buildVolumeOptions(volume.Volume),
785-
TmpfsOptions: buildTmpfsOptions(volume.Tmpfs),
785+
BindOptions: bind,
786+
VolumeOptions: vol,
787+
TmpfsOptions: tmpfs,
786788
}, nil
787789
}
788790

791+
func buildMountOptions(volume types.ServiceVolumeConfig) (*mount.BindOptions, *mount.VolumeOptions, *mount.TmpfsOptions) {
792+
switch volume.Type {
793+
case "bind":
794+
if volume.Volume != nil {
795+
logrus.Warnf("mount of type `bind` should not define `volume` option")
796+
}
797+
if volume.Tmpfs != nil {
798+
logrus.Warnf("mount of type `tmpfs` should not define `tmpfs` option")
799+
}
800+
return buildBindOption(volume.Bind), nil, nil
801+
case "volume":
802+
if volume.Bind != nil {
803+
logrus.Warnf("mount of type `volume` should not define `bind` option")
804+
}
805+
if volume.Tmpfs != nil {
806+
logrus.Warnf("mount of type `volume` should not define `tmpfs` option")
807+
}
808+
return nil, buildVolumeOptions(volume.Volume), nil
809+
case "tmpfs":
810+
if volume.Bind != nil {
811+
logrus.Warnf("mount of type `tmpfs` should not define `bind` option")
812+
}
813+
if volume.Tmpfs != nil {
814+
logrus.Warnf("mount of type `tmpfs` should not define `volumeZ` option")
815+
}
816+
return nil, nil, buildTmpfsOptions(volume.Tmpfs)
817+
}
818+
return nil, nil, nil
819+
}
820+
789821
func buildBindOption(bind *types.ServiceVolumeBind) *mount.BindOptions {
790822
if bind == nil {
791823
return nil

0 commit comments

Comments
 (0)