diff --git a/container.go b/container.go index e67c8f5b0b..52d4110ea9 100644 --- a/container.go +++ b/container.go @@ -98,6 +98,7 @@ type HostConfig struct { LxcConf []KeyValuePair PortBindings map[Port][]PortBinding Links []string + PublishAllPorts bool } type BindMap struct { @@ -169,6 +170,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig, flAutoRemove := cmd.Bool("rm", false, "Automatically remove the container when it exits (incompatible with -d)") cmd.Bool("sig-proxy", true, "Proxify all received signal to the process (even in non-tty mode)") cmd.String("name", "", "Assign a name to the container") + flPublishAll := cmd.Bool("P", false, "Publish all exposed ports to the host interfaces") if capabilities != nil && *flMemory > 0 && !capabilities.MemoryLimit { //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, LxcConf: lxcConf, PortBindings: portBindings, Links: flLinks, + PublishAllPorts: *flPublishAll, } if capabilities != nil && *flMemory > 0 && !capabilities.SwapLimit { @@ -1112,6 +1115,9 @@ func (container *Container) allocateNetwork(hostConfig *HostConfig) error { for port := range portSpecs { binding := bindings[port] + if hostConfig.PublishAllPorts && len(binding) == 0 { + binding = append(binding, PortBinding{}) + } for i := 0; i < len(binding); i++ { b := binding[i] nat, err := iface.AllocatePort(port, b) diff --git a/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index c6579da355..2d5d77d95c 100644 --- a/docs/sources/commandline/cli.rst +++ b/docs/sources/commandline/cli.rst @@ -584,6 +584,7 @@ network communication. -expose=[]: Expose a port from the container without publishing it to your host -link="": Add link to another container (name:alias) -name="": Assign the specified name to the container. If no name is specific docker will generate a random name + -P=false: Publish all exposed ports to the host interfaces Examples --------