Browse code

Merge pull request #2492 from dotcloud/publish-all-flag

Add -P flag to publish all exposed ports

Michael Crosby authored on 2013/11/02 02:21:02
Showing 2 changed files
... ...
@@ -98,6 +98,7 @@ type HostConfig struct {
98 98
 	LxcConf         []KeyValuePair
99 99
 	PortBindings    map[Port][]PortBinding
100 100
 	Links           []string
101
+	PublishAllPorts bool
101 102
 }
102 103
 
103 104
 type BindMap struct {
... ...
@@ -169,6 +170,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
169 169
 	flAutoRemove := cmd.Bool("rm", false, "Automatically remove the container when it exits (incompatible with -d)")
170 170
 	cmd.Bool("sig-proxy", true, "Proxify all received signal to the process (even in non-tty mode)")
171 171
 	cmd.String("name", "", "Assign a name to the container")
172
+	flPublishAll := cmd.Bool("P", false, "Publish all exposed ports to the host interfaces")
172 173
 
173 174
 	if capabilities != nil && *flMemory > 0 && !capabilities.MemoryLimit {
174 175
 		//fmt.Fprintf(stdout, "WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.\n")
... ...
@@ -328,6 +330,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
328 328
 		LxcConf:         lxcConf,
329 329
 		PortBindings:    portBindings,
330 330
 		Links:           flLinks,
331
+		PublishAllPorts: *flPublishAll,
331 332
 	}
332 333
 
333 334
 	if capabilities != nil && *flMemory > 0 && !capabilities.SwapLimit {
... ...
@@ -1112,6 +1115,9 @@ func (container *Container) allocateNetwork(hostConfig *HostConfig) error {
1112 1112
 
1113 1113
 	for port := range portSpecs {
1114 1114
 		binding := bindings[port]
1115
+		if hostConfig.PublishAllPorts && len(binding) == 0 {
1116
+			binding = append(binding, PortBinding{})
1117
+		}
1115 1118
 		for i := 0; i < len(binding); i++ {
1116 1119
 			b := binding[i]
1117 1120
 			nat, err := iface.AllocatePort(port, b)
... ...
@@ -584,6 +584,7 @@ network communication.
584 584
       -expose=[]: Expose a port from the container without publishing it to your host
585 585
       -link="": Add link to another container (name:alias)
586 586
       -name="": Assign the specified name to the container. If no name is specific docker will generate a random name
587
+      -P=false: Publish all exposed ports to the host interfaces
587 588
 
588 589
 Examples
589 590
 --------