8000 1962 invalid port by latiif · Pull Request #2227 · docker/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

1962 invalid port #2227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,14 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
var ports map[nat.Port]struct{}
var portBindings map[nat.Port][]nat.PortBinding

isAdvanced := strings.Contains(strings.Join(publishOpts[:], ""), "=")

ports, portBindings, err = nat.ParsePortSpecs(publishOpts)

if err != nil && !isAdvanced {
return nil, err
}

// If simple port parsing fails try to parse as long format
if err != nil {
publishOpts, err = parsePortOpts(publishOpts)
Expand Down
13 changes: 13 additions & 0 deletions cli/command/container/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ func TestParseHostnameDomainname(t *testing.T) {
}
}

func TestParseWithShorthandPublish(t *testing.T) {
invalids := map[string]string{
":": "No port specified: :<empty>",
"80809:80": "Invalid hostPort: 80809",
"8080:80809": "Invalid containerPort: 80809",
}
for publish, expectedError := range invalids {
if _, _, _, err := parseRun([]string{fmt.Sprintf("-p %v", publish), "img", "cmd"}); err == nil || err.Error() != expectedError {
t.Fatalf("Expected error '%v' with '-p %v', got '%v'", expectedError, publish, err)
}
}
}

func TestParseWithExpose(t *testing.T) {
invalids := map[string]string{
":": "invalid port format for --expose: :",
Expand Down
0