Allow port mapping only for endpoint created on docker run

Signed-off-by: Santhosh Manohar <santhosh@docker.com>
Upstream-commit: dedcf6a6ff6d3aa75efaeb31c197b1c3a19305be
Component: engine
This commit is contained in:
Santhosh Manohar
2015-11-06 13:54:17 -08:00
parent 320a0d9081
commit 4955633439
2 changed files with 34 additions and 5 deletions
+14 -5
View File
@@ -611,7 +611,9 @@ func (container *Container) buildPortMapInfo(ep libnetwork.Endpoint, networkSett
return networkSettings, nil
}
networkSettings.Ports = nat.PortMap{}
if networkSettings.Ports == nil {
networkSettings.Ports = nat.PortMap{}
}
if expData, ok := driverInfo[netlabel.ExposedPorts]; ok {
if exposedPorts, ok := expData.([]types.TransportPort); ok {
@@ -810,6 +812,17 @@ func (container *Container) buildCreateEndpointOptions(n libnetwork.Network) ([]
createOptions []libnetwork.EndpointOption
)
if n.Name() == "bridge" || container.NetworkSettings.IsAnonymousEndpoint {
createOptions = append(createOptions, libnetwork.CreateOptionAnonymous())
}
// Other configs are applicable only for the endpoint in the network
// to which container was connected to on docker run.
if n.Name() != container.hostConfig.NetworkMode.NetworkName() &&
!(n.Name() == "bridge" && container.hostConfig.NetworkMode.IsDefault()) {
return createOptions, nil
}
if container.Config.ExposedPorts != nil {
portSpecs = container.Config.ExposedPorts
}
@@ -879,10 +892,6 @@ func (container *Container) buildCreateEndpointOptions(n libnetwork.Network) ([]
createOptions = append(createOptions, libnetwork.EndpointOptionGeneric(genericOption))
}
if n.Name() == "bridge" || container.NetworkSettings.IsAnonymousEndpoint {
createOptions = append(createOptions, libnetwork.CreateOptionAnonymous())
}
return createOptions, nil
}