defaultRule to get the service name without the stack

labels:
  - '--providers.docker.defaultrule=Host(`{{ index .Labels "com.docker.swarm.service.name" | trimPrefix (index .Labels "com.docker.stack.namespace") | trimPrefix "_" }}.docker.localhost`)'
labels:
  - '--providers.docker.defaultrule=PathPrefix(`/{{ index .Labels "com.docker.swarm.service.name" | trimPrefix (index .Labels "com.docker.stack.namespace") | trimPrefix "_" }}`)'

Note:

  • I use simple quote ' to "wrap" the label
  • I use double qoutes " for the strings

Doc:

1 Like