-
Notifications
You must be signed in to change notification settings - Fork 19.1k
adding support for port ranges on --expose #8167
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,7 @@ func Parse(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config, | |
| cmd.Var(&flEnvFile, []string{"-env-file"}, "Read in a line delimited file of environment variables") | ||
|
|
||
| cmd.Var(&flPublish, []string{"p", "-publish"}, fmt.Sprintf("Publish a container's port to the host\nformat: %s\n(use 'docker port' to see the actual mapping)", nat.PortSpecTemplateFormat)) | ||
| cmd.Var(&flExpose, []string{"#expose", "-expose"}, "Expose a port from the container without publishing it to your host") | ||
| cmd.Var(&flExpose, []string{"#expose", "-expose"}, "Expose a port or a range of ports (e.g. --expose=3300-3310) from the container without publishing it to your host") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the text that should be used in I have a script that will update it for you (though you need to ignore some of its changes) - |
||
| cmd.Var(&flDns, []string{"#dns", "-dns"}, "Set custom DNS servers") | ||
| cmd.Var(&flDnsSearch, []string{"-dns-search"}, "Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)") | ||
| cmd.Var(&flExtraHosts, []string{"-add-host"}, "Add a custom host-to-IP mapping (host:ip)") | ||
|
|
@@ -197,9 +197,24 @@ func Parse(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config, | |
| if strings.Contains(e, ":") { | ||
| return nil, nil, cmd, fmt.Errorf("Invalid port format for --expose: %s", e) | ||
| } | ||
| p := nat.NewPort(nat.SplitProtoPort(e)) | ||
| if _, exists := ports[p]; !exists { | ||
| ports[p] = struct{}{} | ||
| //support two formats for expose, original format <portnum>/[<proto>] or <startport-endport>/[<proto>] | ||
| if strings.Contains(e, "-") { | ||
| proto, port := nat.SplitProtoPort(e) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this parsing should go into a separate function?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, at this point this code is not used by anyone else, if I do support -p option I would prefer to factor. What do you think? |
||
| //parse the start and end port and create a sequence of ports to expose | ||
| parts := strings.Split(port, "-") | ||
| start, _ := strconv.Atoi(parts[0]) | ||
| end, _ := strconv.Atoi(parts[1]) | ||
| for i := start; i <= end; i++ { | ||
| p := nat.NewPort(proto, strconv.Itoa(i)) | ||
| if _, exists := ports[p]; !exists { | ||
| ports[p] = struct{}{} | ||
| } | ||
| } | ||
| } else { | ||
| p := nat.NewPort(nat.SplitProtoPort(e)) | ||
| if _, exists := ports[p]; !exists { | ||
| ports[p] = struct{}{} | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you didn't make this wording, but maybe we can change this now. ping @SvenDowideit
I think this whole paragraph is not right. Technically
exposedoesn't make any ports available inside the container.Or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SvenDowideit waiting for confirmation on the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @cpuguy83 -
exposeindicates to docker that there is something that it can 'link' - I find it a bit confused because I can set updocker run -p 1234:2134on non-exposed ports too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't hold up this PR for that tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased it, code should be ready for merge