# Service port in docker label

**URL:** <https://community.traefik.io/t/service-port-in-docker-label/1624>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [September 17, 2019, 8:46am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624 "2019-09-17T08:46:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@Fred](https://community.traefik.io/u/Fred)\
**Post date:** [September 17, 2019, 8:46am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/1 "2019-09-17T08:46:28Z")

</div>

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

```auto
- "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?

---

<div class="post-metadata">

**Author:** ![igromanru](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/igromanru/32/688_2.png) [@igromanru](https://community.traefik.io/u/igromanru)\
**Post date:** [September 17, 2019, 8:50am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/2 "2019-09-17T08:50:56Z")

</div>

For traefik 2.0:  
`- "traefik.http.services.(service name here).loadbalancer.server.port=8765"`

---

<div class="post-metadata">

**Author:** ![Inigo4562](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@Inigo4562](https://community.traefik.io/u/Inigo4562)\
**Post date:** [September 17, 2019, 8:59am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/3 "2019-09-17T08:59:21Z")

</div>

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

```auto
labels:
  traefik.port: "8765"

```

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [September 17, 2019, 9:02am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/4 "2019-09-17T09:02:30Z")

</div>

> [@Inigo4562](#):
>
> traefik.port

`traefik.port` is not supported in v2.

---

<div class="post-metadata">

**Author:** ![igromanru](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/igromanru/32/688_2.png) [@igromanru](https://community.traefik.io/u/igromanru)\
**Post date:** [September 17, 2019, 9:26am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/5 "2019-09-17T09:26:20Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@Fred](https://community.traefik.io/u/Fred)\
**Post date:** [September 17, 2019, 9:33am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/6 "2019-09-17T09:33:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [September 17, 2019, 9:37am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/7 "2019-09-17T09:37:15Z")

</div>

> [@Fred](#):
>
> 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.)

---

<div class="post-metadata">

**Author:** ![Fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@Fred](https://community.traefik.io/u/Fred)\
**Post date:** [September 17, 2019, 9:42am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/8 "2019-09-17T09:42:26Z")

</div>

@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` ?

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [September 17, 2019, 9:44am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/9 "2019-09-17T09:44:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fred](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@Fred](https://community.traefik.io/u/Fred)\
**Post date:** [September 17, 2019, 9:54am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/10 "2019-09-17T09:54:57Z")

</div>

With this it also does not work:

> **[Compose file version 3 reference](https://docs.docker.com/compose/compose-file/#expose)**
>
> Reference and guidelines These topics describe version 3 of the Compose file format. This is the newest version. Compose and Docker compatibility matrix There are several versions of the Compose...

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).

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [September 17, 2019, 11:59am UTC](https://community.traefik.io/t/service-port-in-docker-label/1624/11 "2019-09-17T11:59:23Z")

</div>

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