From 53ae64e578d73b740e9d85aacd94d2267971264b Mon Sep 17 00:00:00 2001 From: Erin Dachtler Date: Sat, 28 May 2016 15:16:57 -0700 Subject: [PATCH] Filter containers with no exposed ports unless they have a traefik.port label --- provider/docker.go | 6 +++--- provider/docker_test.go | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/provider/docker.go b/provider/docker.go index 7169f20e1..3c7fe8f38 100644 --- a/provider/docker.go +++ b/provider/docker.go @@ -196,11 +196,11 @@ func (provider *Docker) loadDockerConfig(containersInspected []dockertypes.Conta } func containerFilter(container dockertypes.ContainerJSON) bool { - if len(container.NetworkSettings.Ports) == 0 { - log.Debugf("Filtering container without port %s", container.Name) + _, err := strconv.Atoi(container.Config.Labels["traefik.port"]) + if len(container.NetworkSettings.Ports) == 0 && err != nil { + log.Debugf("Filtering container without port and no traefik.port label %s", container.Name) return false } - _, err := strconv.Atoi(container.Config.Labels["traefik.port"]) if len(container.NetworkSettings.Ports) > 1 && err != nil { log.Debugf("Filtering container with more than 1 port and no traefik.port label %s", container.Name) return false diff --git a/provider/docker_test.go b/provider/docker_test.go index 9fd52ce43..417a120d4 100644 --- a/provider/docker_test.go +++ b/provider/docker_test.go @@ -250,6 +250,20 @@ func TestDockerGetPort(t *testing.T) { // }, // expected: "80", // }, + { + container: docker.ContainerJSON{ + ContainerJSONBase: &docker.ContainerJSONBase{ + Name: "test", + }, + Config: &container.Config{ + Labels: map[string]string{ + "traefik.port": "8080", + }, + }, + NetworkSettings: &docker.NetworkSettings{}, + }, + expected: "8080", + }, { container: docker.ContainerJSON{ ContainerJSONBase: &docker.ContainerJSONBase{ @@ -263,7 +277,7 @@ func TestDockerGetPort(t *testing.T) { NetworkSettings: &docker.NetworkSettings{ NetworkSettingsBase: docker.NetworkSettingsBase{ Ports: nat.PortMap{ - "80/tcp": {}, // TODO: Change so there is no exposed port + "80/tcp": {}, }, }, },