diff --git a/bridge/bridge.go b/bridge/bridge.go index c599af24..f3d572f5 100644 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -323,6 +323,18 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service { } } + if b.config.UseIpFromNetwork != "" { + containerNetwork, ok := container.NetworkSettings.Networks[b.config.UseIpFromNetwork] + if ok { + service.IP = containerNetwork.IPAddress + log.Printf("using container IP %s from network '%s'", + service.IP, b.config.UseIpFromLabel) + } else { + log.Printf("Network '%s' not found in container configuration.", + b.config.UseIpFromNetwork) + } + } + // NetworkMode can point to another container (kuberenetes pods) networkMode := container.HostConfig.NetworkMode if networkMode != "" { diff --git a/bridge/types.go b/bridge/types.go index 78c50b3e..10a40946 100644 --- a/bridge/types.go +++ b/bridge/types.go @@ -21,16 +21,17 @@ type RegistryAdapter interface { } type Config struct { - HostIp string - Internal bool - Explicit bool - UseIpFromLabel string - ForceTags string - RefreshTtl int - RefreshInterval int - DeregisterCheck string - Cleanup bool - CleanupDyingTtl int + HostIp string + Internal bool + Explicit bool + UseIpFromLabel string + UseIpFromNetwork string + ForceTags string + RefreshTtl int + RefreshInterval int + DeregisterCheck string + Cleanup bool + CleanupDyingTtl int } type Service struct { diff --git a/registrator.go b/registrator.go index 2f85b8c6..d71cb67b 100644 --- a/registrator.go +++ b/registrator.go @@ -23,6 +23,7 @@ var hostIp = flag.String("ip", "", "IP for ports mapped to the host") var internal = flag.Bool("internal", false, "Use internal ports instead of published ones") var explicit = flag.Bool("explicit", false, "Only register containers which have SERVICE_NAME label set") var useIpFromLabel = flag.String("useIpFromLabel", "", "Use IP which is stored in a label assigned to the container") +var useIpFromNetwork = flag.String("useIpFromNetwork", "", "Use IP that is assigned on to a containers network") var refreshInterval = flag.Int("ttl-refresh", 0, "Frequency with which service TTLs are refreshed") var refreshTtl = flag.Int("ttl", 0, "TTL for services (default is no expiry)") var forceTags = flag.String("tags", "", "Append tags for all registered services") @@ -105,16 +106,17 @@ func main() { } b, err := bridge.New(docker, flag.Arg(0), bridge.Config{ - HostIp: *hostIp, - Internal: *internal, - Explicit: *explicit, - UseIpFromLabel: *useIpFromLabel, - ForceTags: *forceTags, - RefreshTtl: *refreshTtl, - RefreshInterval: *refreshInterval, - DeregisterCheck: *deregister, - Cleanup: *cleanup, - CleanupDyingTtl: *cleanupDyingTtl, + HostIp: *hostIp, + Internal: *internal, + Explicit: *explicit, + UseIpFromLabel: *useIpFromLabel, + UseIpFromNetwork: *useIpFromNetwork, + ForceTags: *forceTags, + RefreshTtl: *refreshTtl, + RefreshInterval: *refreshInterval, + DeregisterCheck: *deregister, + Cleanup: *cleanup, + CleanupDyingTtl: *cleanupDyingTtl, }) assert(err)