# Need help to get the correct container name as subdomain

**URL:** <https://community.traefik.io/t/need-help-to-get-the-correct-container-name-as-subdomain/2621>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [October 26, 2019, 10:21pm UTC](https://community.traefik.io/t/need-help-to-get-the-correct-container-name-as-subdomain/2621 "2019-10-26T22:21:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuro](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/shuro/32/996_2.png) [@Shuro](https://community.traefik.io/u/Shuro)\
**Post date:** [October 26, 2019, 10:21pm UTC](https://community.traefik.io/t/need-help-to-get-the-correct-container-name-as-subdomain/2621/1 "2019-10-26T22:21:00Z")

</div>

Hi there,  
I'm quite new to docker and also to traefik2.

I deployed some containers with docker-compose:

```auto
services:
  traefik:
    container_name: traefik
    image: traefik:v2.0
    restart: always
    volumes:
      - ./traefik.toml:/etc/traefik/traefik.toml
      - /var/run/docker.sock:/var/run/docker.sock:ro
    labels:
      - "traefik.enable=true"
      - "traefik.http.middlewares.auth.basicauth.users=username:REDACTED"
      - "traefik.http.routers.traefik.middlewares=auth"
      - "traefik.http.routers.traefik.service=api@internal"
    ports:
      - "80:80"
      - "443:443"
    networks:
      - default
      - traefik

  whoami:
    image: "containous/whoami"
    container_name: "simple-service"
    labels:
      - "traefik.enable=true"
    networks:
      - traefik

networks:
  traefik:
    external: true

```

My traefik config looks like this:

```auto
[global]
  checkNewVersion = true
  sendAnonymousUsage = false

[entryPoints]
  [entryPoints.web]
    address = ":80"

[log]

[accessLog]

[api]
  dashboard = true
  insecure = false

[ping]

[providers.docker]
  defaultRule = "Host(`{{ normalize .Name }}.my.domain`)"
  exposedByDefault = false

```

I would expect that the Containers get rules like `traefik.my.domain` or `whoami.my.domain`, but they actually are `traefik-root.my.domain` or `whoami-root.my.domain`.

Does someone know how i can fix this without having to define the rule for every container?

---

<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:** [October 26, 2019, 11:25pm UTC](https://community.traefik.io/t/need-help-to-get-the-correct-container-name-as-subdomain/2621/2 "2019-10-26T23:25:39Z")

</div>

Hello,

you use `.Labels`

```auto
[providers.docker]
 defaultRule = "Host(`{{ index .Labels \"com.docker.compose.project\" }}.my.domain`)"

```

---

<div class="post-metadata">

**Author:** ![Shuro](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/shuro/32/996_2.png) [@Shuro](https://community.traefik.io/u/Shuro)\
**Post date:** [October 26, 2019, 11:52pm UTC](https://community.traefik.io/t/need-help-to-get-the-correct-container-name-as-subdomain/2621/3 "2019-10-26T23:52:29Z")

</div>

Isn't that exactly the label I don't want?

```auto
~> docker inspect traefik |grep project
"com.docker.compose.project": "root",

```

---

<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:** [October 26, 2019, 11:53pm UTC](https://community.traefik.io/t/need-help-to-get-the-correct-container-name-as-subdomain/2621/4 "2019-10-26T23:53:15Z")

</div>

so `com.docker.compose.service`
