Use Node IP in Swarm Standalone with "host" NetworkMode

This commit is contained in:
Blake Mesdag 2017-10-25 14:20:03 -04:00 committed by Traefiker
parent 7c4353a0ac
commit d1d8b01dfb
3 changed files with 29 additions and 2 deletions

View file

@ -63,6 +63,7 @@ type dockerData struct {
Labels map[string]string // List of labels set to container or service
NetworkSettings networkSettings
Health string
Node *dockertypes.ContainerNode
}
// NetworkSettings holds the networks data to the Provider p
@ -596,9 +597,13 @@ func (p *Provider) getIPAddress(container dockerData) string {
}
}
// If net==host, quick n' dirty, we return 127.0.0.1
// This will work locally, but will fail with swarm.
if "host" == container.NetworkSettings.NetworkMode {
if container.Node != nil {
if container.Node.IPAddress != "" {
return container.Node.IPAddress
}
}
return "127.0.0.1"
}
@ -823,6 +828,7 @@ func parseContainer(container dockertypes.ContainerJSON) dockerData {
if container.ContainerJSONBase != nil {
dockerData.Name = container.ContainerJSONBase.Name
dockerData.ServiceName = dockerData.Name //Default ServiceName to be the container's Name.
dockerData.Node = container.ContainerJSONBase.Node
if container.ContainerJSONBase.HostConfig != nil {
dockerData.NetworkSettings.NetworkMode = container.ContainerJSONBase.HostConfig.NetworkMode