diff --git a/cli/command/stack/deploy.go b/cli/command/stack/deploy.go index 00a7634a0a..4e7e1242b1 100644 --- a/cli/command/stack/deploy.go +++ b/cli/command/stack/deploy.go @@ -359,7 +359,15 @@ func convertVolumeToMount( 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/cli/command/stack/deploy_test.go b/cli/command/stack/deploy_test.go new file mode 100644 index 0000000000..0ba27c8d0b --- /dev/null +++ b/cli/command/stack/deploy_test.go @@ -0,0 +1,21 @@ +package stack + +import ( + "testing" + + composetypes "github.com/aanand/compose-file/types" + "github.com/docker/docker/api/types/mount" + "github.com/docker/docker/pkg/testutil/assert" +) + +func TestConvertVolumeToMountAnonymousVolume(t *testing.T) { + stackVolumes := map[string]composetypes.VolumeConfig{} + namespace := namespace{name:"foo"} + expected := mount.Mount{ + Type: mount.TypeVolume, + Target: "/foo/bar", + } + mnt, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace) + assert.NilError(t, err) + assert.DeepEqual(t, mnt, expected) +}