From 813cc7ed9c086af2ff6dee8c5b2ca5a15e80451a 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 (cherry picked from commit 154a1f6df8f3ce65f980b47bb4a4ff8c41c4c5c0) 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 19a2d158cc..4f0f8d7c27 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -799,7 +799,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 e8c71e2388..7c08527250 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -854,3 +854,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) +}