Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service {
}

// NetworkMode can point to another container (kuberenetes pods)
var ipFromNetworkContainer string
networkMode := container.HostConfig.NetworkMode
if networkMode != "" {
if strings.HasPrefix(networkMode, "container:") {
Expand All @@ -318,8 +319,28 @@ func (b *Bridge) newService(port ServicePort, isgroup bool) *Service {
if err != nil {
log.Println("unable to inspect network container:", networkContainerId[:12], err)
} else {
service.IP = networkContainer.NetworkSettings.IPAddress
log.Println(service.Name + ": using network container IP " + service.IP)
ipFromNetworkContainer = networkContainer.NetworkSettings.IPAddress

if ipFromNetworkContainer != "" {
service.IP = networkContainer.NetworkSettings.IPAddress
log.Println(service.Name + ": using network container IP " + service.IP)
} else {
log.Println(service.Name + ": network container IP address is empty")
}
}
}
}

// Grab the container IP address from docker or kubernetes env
if b.config.UseIpFromEnv != "" && ipFromNetworkContainer == "" {
for _, requiredEnv := range container.Config.Env {
if strings.Contains(requiredEnv, b.config.UseIpFromEnv) {
service.IP = requiredEnv[len(b.config.UseIpFromEnv)+1:]
log.Println(service.Name + ": using container IP '" + service.IP +
"' from env '" + b.config.UseIpFromEnv + "'")
} else {
log.Println(service.Name + ": could not found env '" + b.config.UseIpFromEnv +
"' from docker env")
}
}
}
Expand Down
1 change: 1 addition & 0 deletions bridge/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
HostIp string
Internal bool
UseIpFromLabel string
UseIpFromEnv string
ForceTags string
RefreshTtl int
RefreshInterval int
Expand Down
1 change: 1 addition & 0 deletions docs/user/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Option | Since | Description
`-ttl <seconds>` | | TTL for services. Default: 0, no expiry (supported backends only)
`-ttl-refresh <seconds>` | | Frequency service TTLs are refreshed (supported backends only)
`-useIpFromLabel <label>` | | Uses the IP address stored in the given label, which is assigned to a container, for registration with Consul
`-useIpFromEnv <env>` | | Uses the IP address from the given environment variable, which is assigned to a container, for registration with Consul

If the `-internal` option is used, Registrator will register the docker0
internal IP and port instead of the host mapped ones.
Expand Down
1 change: 1 addition & 0 deletions registrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var versionChecker = usage.NewChecker("registrator", Version)
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 useIpFromLabel = flag.String("useIpFromLabel", "", "Use IP which is stored in a label assigned to the container")
var useIpFromEnv = flag.String("useIpFromEnv", "", "Use IP from the container environment variable")
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")
Expand Down