Add support for reaching containers using host networking on Podman

This commit is contained in:
Adrian Freund 2022-07-19 16:22:08 +02:00 committed by GitHub
parent cdda9a18ab
commit f85f3b68aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -133,7 +133,8 @@ 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`
- if the lookup was unsuccessful, fall back to `127.0.0.1`
- if the lookup was unsuccessful, try a lookup of `host.containers.internal`, ([Podman](https://docs.podman.io/en/latest/) equivalent of `host.docker.internal`)
- if that lookup was also unsuccessful, fall back to `127.0.0.1`
On Linux, for versions of Docker older than 20.10.0, 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

View file

@ -338,6 +338,9 @@ func (p Provider) getIPAddress(ctx context.Context, container dockerData) string
if host, err := net.LookupHost("host.docker.internal"); err == nil {
return host[0]
}
if host, err := net.LookupHost("host.containers.internal"); err == nil {
return host[0]
}
return "127.0.0.1"
}