diff --git a/compose/convert/volume.go b/compose/convert/volume.go index 4eb5788204..027774bcec 100644 --- a/compose/convert/volume.go +++ b/compose/convert/volume.go @@ -42,7 +42,15 @@ func convertVolumeToMount(volumeSpec string, stackVolumes volumes, namespace Nam case 1: target = parts[0] default: - return mount.Mount{}, fmt.Errorf("invald volume: %s", volumeSpec) + return mount.Mount{}, fmt.Errorf("invalid volume: %s", volumeSpec) + } + + if source == "" { + // Anonymous volume + return mount.Mount{ + Type: mount.TypeVolume, + Target: target, + }, nil } // TODO: catch Windows paths here diff --git a/compose/convert/volume_test.go b/compose/convert/volume_test.go index 5e9c042b5f..3ca6ab4a52 100644 --- a/compose/convert/volume_test.go +++ b/compose/convert/volume_test.go @@ -34,6 +34,18 @@ func TestGetBindOptionsNone(t *testing.T) { assert.Equal(t, opts, (*mount.BindOptions)(nil)) } +func TestConvertVolumeToMountAnonymousVolume(t *testing.T) { + stackVolumes := volumes{} + namespace := NewNamespace("foo") + expected := mount.Mount{ + Type: mount.TypeVolume, + Target: "/foo/bar", + } + mount, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace) + assert.NilError(t, err) + assert.DeepEqual(t, mount, expected) +} + func TestConvertVolumeToMountNamedVolume(t *testing.T) { stackVolumes := volumes{ "normal": composetypes.VolumeConfig{