Need some "macro expansion" in my docker-compose labels

Quite often I find my self copying a project to a new instance to try something out.

In it's cleanest form this is just to create a new directory and copy over the docker-compose file. Ideally I would then only have to adjust the exposed hostname and be ready to run. And example is shown below.

version: '3'

services:
  service_A:
    image: traefik/whoami

    labels:
      - "traefik.http.routers.__SA__.rule=Host(`serviceA.example.com`)"
      - "traefik.http.routers.__SA__.tls=true"
      - "traefik.http.routers.__SA__.tls.certresolver=lets-encrypt"
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"

    networks:
      - traefik

  service_B:
    image: traefik/whoami

    labels:
      - "traefik.http.routers.__SB__.rule=Host(`serviceB.example.com`)"
      - "traefik.http.routers.__SB__.tls=true"
      - "traefik.http.routers.__SB__.tls.certresolver=lets-encrypt"
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"

    networks:
      - traefik

networks:
  traefik:
    external: true

What bugs me is that I have to edit the __SA__ and the __SB__ to make sure they are unique under the whole traefik umbrella.

The same goes if I just want to add service_C to the example above, then I have to make sure I pick something unique for the labels.

I would like to put in a variable instead, something like ${FILE_AND_SERVICE}
I have never needed to reference those names from outside the actual service.

Can it be done in a not too hackish way?

You can place tls, certresolver and docker.network on your entrypoint. Don't even need tls when using LE. Then you only have Host() and enable per container. See simple example.

You can get rid of enable if you want all Docker services to be auto discovered.

Interesting. And you dont have traefik.toml and traefik_dynamic.toml files at all?
Would like to get rid of those in my setup.