From 154a1f6df8f3ce65f980b47bb4a4ff8c41c4c5c0 Mon Sep 17 00:00:00 2001 From: Nick Adcock Date: Tue, 14 Jan 2020 15:44:47 +0000 Subject: [PATCH] Reverse order of long-form ports Reverses the order long-form port options when converted to short-form to correctly match the documentation and `docker service create`. Post change `-p published=8111,target=8112` is the equivalent of `8111:8112` Signed-off-by: Nick Adcock --- cli/command/container/opts.go | 2 +- cli/command/container/opts_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 157e1bedc7..5ae7e8cc01 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -808,7 +808,7 @@ func parsePortOpts(publishOpts []string) ([]string, error) { params[opt[0]] = opt[1] } - optsList = append(optsList, fmt.Sprintf("%s:%s/%s", params["target"], params["published"], params["protocol"])) + optsList = append(optsList, fmt.Sprintf("%s:%s/%s", params["published"], params["target"], params["protocol"])) } return optsList, nil } diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index 709119c5f7..46a4ba5192 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -872,3 +872,9 @@ func TestParseSystemPaths(t *testing.T) { assert.DeepEqual(t, readonlyPaths, tc.readonly) } } + +func TestParsePortOpts(t *testing.T) { + parsed, err := parsePortOpts([]string{"published=1500,target=200", "target=80,published=90"}) + assert.NilError(t, err) + assert.DeepEqual(t, []string{"1500:200/tcp", "90:80/tcp"}, parsed) +}