Implemented host_network_host setting
@@ -54,6 +54,7 @@ var DefaultDockerSDConfig = DockerSDConfig{
RefreshInterval: model.Duration(60 * time.Second),
Port: 80,
Filters: []Filter{},
+ HostNetworkHost: "localhost",
HTTPClientConfig: config.DefaultHTTPClientConfig,
}
@@ -68,6 +69,7 @@ type DockerSDConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Filters []Filter `yaml:"filters"`
+ HostNetworkHost string `yaml:"host_network_host"`
RefreshInterval model.Duration `yaml:"refresh_interval"`
}
@@ -106,6 +108,7 @@ type DockerDiscovery struct {
*refresh.Discovery
client *client.Client
port int
+ hostNetworkHost string
filters filters.Args
}
@@ -115,6 +118,7 @@ func NewDockerDiscovery(conf *DockerSDConfig, logger log.Logger) (*DockerDiscove
d := &DockerDiscovery{
port: conf.Port,
+ hostNetworkHost: conf.HostNetworkHost,
}
hostURL, err := url.Parse(conf.Host)
@@ -245,7 +249,15 @@ func (d *DockerDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, er
labels[model.LabelName(k)] = model.LabelValue(v)
}
- addr := net.JoinHostPort(n.IPAddress, strconv.FormatUint(uint64(d.port), 10))
+ // Containers in host networking mode don't have ports,
+ // so they only end up here, not in the previous loop.
+ var addr string
+ if c.HostConfig.NetworkMode != "host" {
+ addr = net.JoinHostPort(n.IPAddress, strconv.FormatUint(uint64(d.port), 10))
+ } else {
+ addr = d.hostNetworkHost
+ }
+
labels[model.AddressLabel] = model.LabelValue(addr)
tg.Targets = append(tg.Targets, labels)
}
