From 050416224d6bf90ae0b7d3ae9948e45c1ffd3631 Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Tue, 5 Jul 2016 11:16:47 +0200 Subject: [PATCH 1/3] Fix host Docker network Signed-off-by: Emile Vauge --- provider/docker.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/provider/docker.go b/provider/docker.go index 3764eb808..8e5f4cd09 100644 --- a/provider/docker.go +++ b/provider/docker.go @@ -270,7 +270,12 @@ func (provider *Docker) getIPAddress(container dockertypes.ContainerJSON) string } } } - for _, network := range container.NetworkSettings.Networks { + for networkName, network := range container.NetworkSettings.Networks { + // If net==host, quick n' dirty, we return 127.0.0.1 + // This will work locally, but will fail with swarm. + if "host" == networkName { + return "127.0.0.1" + } return network.IPAddress } return "" From 6fd89797540f177b4a916b24a36c1f76d9316189 Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Tue, 5 Jul 2016 11:26:59 +0200 Subject: [PATCH 2/3] Remove deprecated traefik.domain label Signed-off-by: Emile Vauge --- docs/toml.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/toml.md b/docs/toml.md index 279acecda..b3106aacf 100644 --- a/docs/toml.md +++ b/docs/toml.md @@ -541,7 +541,6 @@ Labels can be used on containers to override default behaviour: - `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend. - `traefik.frontend.priority=10`: override default frontend priority - `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`. -- `traefik.domain=traefik.localhost`: override the default domain - `traefik.docker.network`: Set the docker network to use for connections to this container @@ -576,7 +575,6 @@ endpoint = "http://127.0.0.1:8080" watch = true # Default domain used. -# Can be overridden by setting the "traefik.domain" label on an application. # # Required # @@ -638,7 +636,6 @@ Labels can be used on containers to override default behaviour: - `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend. - `traefik.frontend.priority=10`: override default frontend priority - `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`. -- `traefik.domain=traefik.localhost`: override the default domain ## Kubernetes Ingress backend From b1ecb1f61f0953d6a057d56e5cdd3ec168990613 Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Tue, 5 Jul 2016 11:44:30 +0200 Subject: [PATCH 3/3] Use of container.HostConfig.NetworkMode to detect host mode Signed-off-by: Emile Vauge --- provider/docker.go | 14 ++++++++------ provider/docker_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/provider/docker.go b/provider/docker.go index 8e5f4cd09..9b732195e 100644 --- a/provider/docker.go +++ b/provider/docker.go @@ -270,12 +270,14 @@ func (provider *Docker) getIPAddress(container dockertypes.ContainerJSON) string } } } - for networkName, network := range container.NetworkSettings.Networks { - // If net==host, quick n' dirty, we return 127.0.0.1 - // This will work locally, but will fail with swarm. - if "host" == networkName { - return "127.0.0.1" - } + + // If net==host, quick n' dirty, we return 127.0.0.1 + // This will work locally, but will fail with swarm. + if container.HostConfig != nil && "host" == container.HostConfig.NetworkMode { + return "127.0.0.1" + } + + for _, network := range container.NetworkSettings.Networks { return network.IPAddress } return "" diff --git a/provider/docker_test.go b/provider/docker_test.go index 364f0e885..5dad8e030 100644 --- a/provider/docker_test.go +++ b/provider/docker_test.go @@ -269,6 +269,30 @@ func TestDockerGetIPAddress(t *testing.T) { // TODO }, expected: "10.11.12.14", }, + { + container: docker.ContainerJSON{ + ContainerJSONBase: &docker.ContainerJSONBase{ + Name: "bar", + HostConfig: &container.HostConfig{ + NetworkMode: "host", + }, + }, + Config: &container.Config{ + Labels: map[string]string{}, + }, + NetworkSettings: &docker.NetworkSettings{ + Networks: map[string]*network.EndpointSettings{ + "testnet1": { + IPAddress: "10.11.12.13", + }, + "testnet2": { + IPAddress: "10.11.12.14", + }, + }, + }, + }, + expected: "127.0.0.1", + }, } for _, e := range containers {