Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple ports per service not working #1321

Closed
dcrystalj opened this issue Mar 21, 2017 · 23 comments
Closed

Multiple ports per service not working #1321

dcrystalj opened this issue Mar 21, 2017 · 23 comments
Labels
area/provider/docker/swarm kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed. status/5-frozen-due-to-age
Milestone

Comments

@dcrystalj
Copy link

dcrystalj commented Mar 21, 2017

What version of Traefik are you using (traefik version)?

commit 677899d9ff7790c4c2abeb35f7ecba7fa266c74c
cointainer containous/traefik:experimental

What is your environment & configuration (arguments, toml...)?

    docker service create \
        --name traefik \
        --constraint=node.role==manager \
        --publish 80:80 --publish 8080:8080 \
        --mount "type=bind,source={{ remote_config }}/traefik.toml,target=/etc/traefik/traefik.toml" \
        --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
        --network proxy \
        --mode global \
        containous/traefik:experimental \
        --docker \
        --docker.swarmmode \
        --docker.domain=traefik \
        --docker.watch \
        --web

What did you do?

I created simple service as

    docker service create \
    --name=visualizer \
    --network=proxy \
    --constraint=node.role==manager \
    --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
    --label traefik.visualizer.port=8080 \
    --label traefik.visualizer.network=proxy \
    --label traefik.visualizer.frontend.rule=Host:visualizer.traefik \
    --label traefik.visualizer.frontend.entryPoints=http,https \
    manomarks/visualizer:latest

What did you expect to see?

In traefik gui, service visualizer.

What did you see instead?

Nothing


While putting old school label --label traefik.port=8080 is working this .visualizer. as <service-name> is not (--label traefik.visualizer.port=8080).

<service-name> was introduced in #1257

@timoreimann
Copy link
Contributor

@benoitf do you possibly have any idea?

@benoitf
Copy link
Contributor

benoitf commented Mar 21, 2017

AFAIK there is no traefik.<service-name>.network support

traefik.docker.network is the property to connect to a network

@dcrystalj
Copy link
Author

You are right! but its still not working

    docker service create \
    --name=visualizer \
    --network=proxy \
    --constraint=node.role==manager \
    --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
    --label traefik.docker.network=proxy \
    --label traefik.visualizer.port=8080 \
    --label traefik.visualizer.frontend.rule=Host:visualizer.traefik \
    --label traefik.visualizer.frontend.entryPoints=http,https \
    manomarks/visualizer:latest

@benoitf
Copy link
Contributor

benoitf commented Mar 21, 2017

OK i will check but it is looking like if support is not inside the traefik docker image you're using
I don't know if you could tried florentbenoit/traefik image. It's a one I built to test it on my project waiting for 1.3 official release.

@dcrystalj
Copy link
Author

dcrystalj commented Mar 21, 2017

still no luck

    docker service create \
    --name=visualizer \
    --network=proxy \
    --constraint=node.role==manager \
    --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
    --label traefik.docker.network=proxy \
    --label traefik.visualizer.port=8080 \
    --label traefik.visualizer.frontend.rule=Host:visualizer.traefik \
    --label traefik.visualizer.frontend.entryPoints=http,https \
    manomarks/visualizer:latest
ID            NAME           MODE        REPLICAS  IMAGE
dtqn4v4c9jnd  visualizer     replicated  1/1       florentbenoit/traefik:latest

@benoitf
Copy link
Contributor

benoitf commented Mar 21, 2017

@dcrystalj could you enable logLevel with DEBUG ?

@dcrystalj
Copy link
Author

dcrystalj commented Apr 18, 2017

@benoitf

traefik.1.j36czrlk8cea@swarm-02    | time="2017-04-18T12:42:05Z" level=debug msg="Filtering container without port and no traefik.port label visualizer.1" 
traefik.1.j36czrlk8cea@swarm-02    | time="2017-04-18T12:42:05Z" level=debug msg="Filtering container without port and no traefik.port label traefik.1" 
traefik.1.j36czrlk8cea@swarm-02    | time="2017-04-18T12:42:05Z" level=debug msg="Configuration received from provider docker: {}" 
traefik.1.j36czrlk8cea@swarm-02    | time="2017-04-18T12:42:05Z" level=info msg="Skipping same configuration for provider docker" 

This logs are repeating.

@WTFKr0
Copy link
Contributor

WTFKr0 commented May 12, 2017

Hi

Same here

Version:      v1.3.0-rc1
Codename:     raclette
Go version:   go1.8.1
Built:        2017-05-05_02:03:01PM
OS/Arch:      linux/amd64

When I place labels on service like that, it's OK :

        - 'traefik.frontend.rule=Host:s1.mydomain.org'
        - "traefik.port=80"

But like that I got Filtering container without port and no traefik.port label

        - 'traefik.s1.frontend.rule=Host:s1.mydomain.org'
        - "traefik.s1.port=80"
        - 'traefik.s2.frontend.rule=Host:s2.mydomain.org'
        - "traefik.s2.port=8081"

@BSchwetzel
Copy link

BSchwetzel commented May 16, 2017

Same problem here. Compose file:

version: '3.1'
services:
  master:
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role==manager
    command: "--docker --docker.swarmmode --docker.domain=traefik --docker.watch --web --loglevel=DEBUG"
    image: "traefik:v1.3"
    ports:
      - "80:80"
      - "443:443"
      - "8081:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - mynet
networks:
  mynet:
    external: true

(Proxied) Service Inspect:

"Labels": {
                "traefik.config.frontend.rule": "PathPrefixStrip:/geocoding-osm-config",
                "traefik.config.port": "8081",
                "traefik.docker.network": "mynet",
                "traefik.web.frontend.rule": "PathPrefixStrip:/geocoding-osm",
                "traefik.web.port": "8080"
            }

Log output:

time="2017-05-16T09:56:46Z" level=debug msg="Filtering container without port and no traefik.port label geocoding-osm.1"
time="2017-05-16T09:56:46Z" level=debug msg="Filtering container without port and no traefik.port label geocoding-osm.2"

@aantono
Copy link
Contributor

aantono commented May 24, 2017

Could you provide the output of docker inspect <container_id> for your service? Based on the code it appears that the problem might stem from the docker API not returning the NetworkSettings/Ports values in the JSON. This causes the ports data being missing and without the explicit label overrides those containers get filtered out.

@BSchwetzel
Copy link

BSchwetzel commented May 26, 2017

Sure:

docker inspect
[
    {
        "Id": "8197d1e0d076341deaa5432777f35636829723edb2c4ff18597ad2c7ccf8df08",
        "Created": "2017-05-16T09:36:06.482902265Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "exec java -jar -Djava.security.egd=file:/dev/urandom -Dspring.profiles.active=$SPRING_ACTIVE_PROFILE geocoding-osm-1.0.0.jar"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 27817,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-05-16T09:36:07.469431068Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:9a353e4e27107fb63764c92c9b28204a6051ce8a7bb0850d17096e236ecbd193",
        "ResolvConfPath": "/var/lib/docker/containers/8197d1e0d076341deaa5432777f35636829723edb2c4ff18597ad2c7ccf8df08/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/8197d1e0d076341deaa5432777f35636829723edb2c4ff18597ad2c7ccf8df08/hostname",
        "HostsPath": "/var/lib/docker/containers/8197d1e0d076341deaa5432777f35636829723edb2c4ff18597ad2c7ccf8df08/hosts",
        "LogPath": "",
        "Name": "/geocoding-osm.2.vsjfbzpy2tlseti853vxpzpt7",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "gelf",
                "Config": {
                    "env": "SPRING_ACTIVE_PROFILE",
                    "gelf-address": "udp://127.0.0.1:12201",
                    "labels": "com.docker.swarm.service.name"
                }
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": null,
            "Name": "aufs"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "8197d1e0d076",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "SPRING_ACTIVE_PROFILE=development",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DEBIAN_FRONTEND=noninteractive",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre",
            ],
            "Cmd": null,
            "ArgsEscaped": true,
            "Image": "registry.local/myns/geocoding-osm:1.0.0@sha256:5f05790ff2476b65065687c12c70e9dcd5e72ae3e3d021589b54e6c9d4e03e32",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/bin/sh",
                "-c",
                "exec java -jar -Djava.security.egd=file:/dev/urandom -Dspring.profiles.active=$SPRING_ACTIVE_PROFILE geocoding-osm-1.0.0.jar"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.swarm.node.id": "xtky7938ptpf0k41peyd2opa8",
                "com.docker.swarm.service.id": "a1onhl095h78bxx2j0g79noq0",
                "com.docker.swarm.service.name": "geocoding-osm",
                "com.docker.swarm.task": "",
                "com.docker.swarm.task.id": "vsjfbzpy2tlseti853vxpzpt7",
                "com.docker.swarm.task.name": "geocoding-osm.2.vsjfbzpy2tlseti853vxpzpt7",
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "67bafaf0afc4382eac53d62bee71b40a10bc63a807cf2d31055c392f4c1f8c59",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/67bafaf0afc4",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "egov": {
                    "IPAMConfig": {
                        "IPv4Address": "10.0.0.33"
                    },
                    "Links": null,
                    "Aliases": [
                        "8197d1e0d076"
                    ],
                    "NetworkID": "elna4snc2j34e68sx3axjli2y",
                    "EndpointID": "c6bfe20b634ae07f2b9178cff011e3cd1153b311f4822fdf18d2e5900cfd90e0",
                    "Gateway": "",
                    "IPAddress": "10.0.0.33",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:0a:00:00:21"
                },
                "ingress": {
                    "IPAMConfig": {
                        "IPv4Address": "10.255.0.41"
                    },
                    "Links": null,
                    "Aliases": [
                        "8197d1e0d076"
                    ],
                    "NetworkID": "x1itm34yur65bgllyopbfaplh",
                    "EndpointID": "887529c8cc0aa5fa58de78408a7a87b8b84336bbd0157be43f80f63906209986",
                    "Gateway": "",
                    "IPAddress": "10.255.0.41",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:0a:ff:00:29"
                }
            }
        }
    }
]

@aantono
Copy link
Contributor

aantono commented May 27, 2017

I'm not entirely sure of a reason as to why, but based on the docker inspect result, it is evident that the NetworkSettings/Ports section is empty, not containing any ports. If Traefik is not able to get ports from Docker, it has no information to use for port mapping, unless an explicit labels are provided.

Do you specify the port mappings when you launch the containers?

@BSchwetzel
Copy link

BSchwetzel commented May 29, 2017

Well, I am providing explicit labels, as shown in the Service Inspect part:

"traefik.config.frontend.rule": "PathPrefixStrip:/geocoding-osm-config",
                "traefik.config.port": "8081",
                "traefik.docker.network": "mynet",
                "traefik.web.frontend.rule": "PathPrefixStrip:/geocoding-osm",
                "traefik.web.port": "8080"

When using traefik.port at exactly the same place it will work (meaning that service labels should be sufficient), but then I am limited to that one port. I thought the "traefik-services" (config and web in this case) were created to remove this limitation? To me it seems that traefik doesn't look for labels matching "traefik.SOMETHING.port" and "traefik.SOMETHING.frontend.rule" when creating its config.

@aantono
Copy link
Contributor

aantono commented May 30, 2017

@BSchwetzel Yes, indeed that looks to be an issue. Seems like containerFilter only honors traefik.port tag and does not look at the service tags (https://github.com/containous/traefik/blob/master/provider/docker/docker.go#L503)

But the question still remains - if the container does not expose any ports (according to the docker inspect), how will the routing actually happen from the networking standpoint? Is the Traefik instance running internally on the docker custom network, so the network calls happen on the inside cross-container, without outside access?

@ldez ldez added kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed. and removed status/0-needs-triage labels Jun 9, 2017
@BSchwetzel
Copy link

BSchwetzel commented Jun 13, 2017

In my case the traefik instance is running inside the swarm and on the same overlay network. Adding EXPOSE to the Dockerfile of the service leads to

"ExposedPorts": {
                "8080/tcp": {},
                "8081/tcp": {}
            },

and

"Ports": {
                "8080/tcp": null,
                "8081/tcp": null
            },

being added to the output of docker inspect, but the traefik log still shows the same problem. So is there something else wrong? As it is a Swarm service, I cannot publish the ports per container.

@aantono
Copy link
Contributor

aantono commented Jun 13, 2017

@ldez, or other maintainers, can probably correct me if I'm wrong, but looks like in this scenario there is no external port being exposed, so currently Traefik is not considering the use-case where no exposed ports have been defined and no traefik.port label exists, but only the service-specific labels do. So it might be a need to add the check for traefik.<service>.port label presence check as well into the containerFilter function.

@thomas15v
Copy link

Not sure but this appears to be fixed in the newest version. I was testing and failing constantly but after a docker pull and restart this compose file suddenly started working.

@BSchwetzel
Copy link

BSchwetzel commented Jul 18, 2017

Weird, with 1.3.3 I'm still getting these log messages. Are you deploying those as standalone containers or to a swarm (using docker stack deploy)? I see you are using "restart: always" in your compose file, so I believe you're not using swarm. I'd assume that it can read your exposed ports then, whereas my deployment, using a swarm service, does not set those ports in the same way and therefore cannot be read correctly by traefik.

@dimk0
Copy link

dimk0 commented Jul 27, 2017

I'm using traefik with swarm and I confirm that defining multiple ports does not work for me either.

@aantono
Copy link
Contributor

aantono commented Aug 9, 2017

I think what needs to happen is to change the port check at the very beginning of containerFilter method to look like this:

        _, err := strconv.Atoi(container.Labels[types.LabelPort])
	if len(container.NetworkSettings.Ports) == 0 && err != nil {
		if p.hasServices(container) {
			foundServicePort := false
			for _, serviceName := range p.getServiceNames(container) {
				if len(p.getServicePort(container, serviceName)) > 0 {
					foundServicePort = true
				}
			}
			if !foundServicePort {
				log.Debugf("Filtering container wihtout port and no traefik.port or traefik.<service>.port label %s", container.Name)
				return false
			}
		} else {
			log.Debugf("Filtering container without port and no traefik.port label %s", container.Name)
			return false
		}
	}

basically adding an extra check to see if service labels are present, in which case to check each service for presence of service port label, otherwise filtering it out.

Thoughts?

@ldez ldez changed the title Multiple ports per service not wokring Multiple ports per service not working Aug 10, 2017
@atecey
Copy link

atecey commented Aug 10, 2017

I experienced a similar problem when trying to use Nexus3 in swarm mode to host multiple Docker repos using a frontend rule per exposed port. In the end up what worked for me was adding the following rules to my nexus3 service. It wouldn't work unless I included a traefik.frontend.rule + port.

v1.3.4 / raclette

traefik.docker.network=nexus3_nexus
traefik.dockergroup.frontend.rule=Host:docker.nexus.local.com
traefik.dockergroup.port=9100
traefik.enable=true
traefik.frontend.rule=Host:ui.nexus.local.com
traefik.nexus.frontend.rule= Host:ui.nexus.local.com
traefik.nexus.port=8081
traefik.port=8081
traefik.internalrepo.frontend.rule=Host:internalrepo.nexus.local.com
traefik.internalrepo.port=9101

@andrewcfitz
Copy link

This also worked for me.

@traefiker
Copy link
Contributor

Closed by #2330.

@traefiker traefiker added this to the 1.4 milestone Oct 30, 2017
@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/provider/docker/swarm kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed. status/5-frozen-due-to-age
Projects
None yet
Development

No branches or pull requests