mirror of
https://github.com/containous/traefik.git
synced 2025-03-22 02:50:13 +03:00
Fix traefik behavior when network_mode is host
This commit is contained in:
parent
115d42e0f0
commit
0c90f6afa2
@ -116,6 +116,20 @@ Ports detection works as follows:
|
||||
by using the label `traefik.http.services.<service_name>.loadbalancer.server.port`
|
||||
(Read more on this label in the dedicated section in [routing](../routing/providers/docker.md#port)).
|
||||
|
||||
### Host networking
|
||||
|
||||
When exposing containers that are configured with [host networking](https://docs.docker.com/network/host/),
|
||||
the IP address of the host is resolved as follows:
|
||||
|
||||
<!-- TODO: verify and document the swarm mode case with container.Node.IPAddress coming from the API -->
|
||||
- try a lookup of `host.docker.internal`
|
||||
- otherwise fall back to `127.0.0.1`
|
||||
|
||||
On Linux, (and until [github.com/moby/moby/pull/40007](https://github.com/moby/moby/pull/40007) is included in a release),
|
||||
for `host.docker.internal` to be defined, it should be provided as an `extra_host` to the Traefik container,
|
||||
using the `--add-host` flag. For example, to set it to the IP address of the bridge interface (docker0 by default):
|
||||
`--add-host=host.docker.internal:172.17.0.1`
|
||||
|
||||
### Docker API Access
|
||||
|
||||
Traefik requires access to the docker socket to get its dynamic configuration.
|
||||
|
@ -259,6 +259,9 @@ func (p Provider) getIPAddress(ctx context.Context, container dockerData) string
|
||||
if container.Node != nil && container.Node.IPAddress != "" {
|
||||
return container.Node.IPAddress
|
||||
}
|
||||
if host, err := net.LookupHost("host.docker.internal"); err == nil {
|
||||
return host[0]
|
||||
}
|
||||
return "127.0.0.1"
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user