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 <nick.adcock@docker.com>
(cherry picked from commit 154a1f6df8)
Signed-off-by: Nick Adcock <nick.adcock@docker.com>
This commit is contained in:
Nick Adcock 2020-01-14 15:44:47 +00:00
parent 2c7de2070e
commit 813cc7ed9c
No known key found for this signature in database
GPG Key ID: 53A3DA819849816E
2 changed files with 7 additions and 1 deletions

View File

@ -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
}

View File

@ -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)
}