Service port in docker label

Sorry guys - this is a real dummies question, but I've not found an example in the docs:

In traefik v1 I have a service in a docker container listening on a particular port.
This is configured in a docker-compose file label

- "traefik.port=8765"

How is this configured in v2, ie what should the label look like? I guess it's a service property? Or is it auto-detected by traefik from docker?

For traefik 2.0:
- " name here).loadbalancer.server.port=8765"

For me it works like this in docker-compose v3:

  traefik.port: "8765"

traefik.port is not supported in v2.

Ah and to answer your last question.
Traefik auto discovers first exposed port. In most cases it's fine, but it's not always what you want.
If you want to get sure, just use a service. (see my first reply)

1 Like

Excellent - thanks for the speedy answers!! I just tested:

I confirm traefik.port does not work in traefik v2 but the line posted by @igromanru does work!

With just one port exposed (via a 'port' enty in my v3 compose file), it does not work without the the port label - so the auto-detection does not appear to work.

Traefik autodiscover port when the container exposes only one port except with Swarm (in this case the port must be define manually.)

@Idez I hear what you are saying, but this did not work for me. Only one port is mapped via

port: "8765:8765"

Or does this only work when using expose ?

It's on container not on service, so yes only works when a container expose a port as the v1.

With this it also does not work:

Only other way I can think of is to use EXPOSE in the Dockerfile - but I'm using a third party image so that's not an option (I don't want to rebuild from a base image).

I misspoke, yes it only works with Docker images that use EXPOSE