1

I usually create my stacks using docker-compose, but when I have a single service, I prefer to create it directly as a service, without the underlying (and useless) stack.

My problem is about the labels I need to set under the "deploy" sections, such as Traefik's ones :

deploy:
  replicas: 1
  labels:
   - "traefik.enable=true"
   - "traefik.gis.frontend.rule=PathPrefix:/sig"
   - "traefik.web.frontend.rule=PathPrefixStrip:/web"
   - "traefik.port=80"
   - "traefik.docker.network=traefik-network"

I don't know to set them through docker service create . This will not work , because Traefik requires that labels are set under deploy section:

docker service create \
    --name myService \
    --with-registry-auth \
    --network traefik-net \
    --label "traefik.enable=true" \
    --label "traefik.gis.frontend.rule=PathPrefix:/sig" \
    --label "traefik.web.frontend.rule=PathPrefixStrip:/web" \
    --label "traefik.port=80" \
    --label "traefik.docker.network=traefik-net" \
    dvgerdrh2:5050/georeso/someImage:1.3.2

Any idea on how to do this?

Marvin
  • 1,650
  • 4
  • 19
  • 41
  • Why you don't use YML and `docker stack deploy...`? – Oleh Vasylyev Oct 04 '18 at 08:59
  • I do, most of the time. But I would like learn how to do the same with docker service create. – Marvin Oct 04 '18 at 09:02
  • Seems like you was on right way, but maybe mistake with double quotes. Look here on example in documentation https://docs.docker.com/engine/reference/commandline/service_create/#set-metadata-on-a-service--l---label – Oleh Vasylyev Oct 04 '18 at 09:10
  • Tried both way, but this didn't work the way I expect : I want the label to be related to "deploy". If I do it the way I tried, the label is associated with the service itself.. and not to the deploy part of it, leading to Traefik not being able to use it correctly – Marvin Oct 04 '18 at 09:13
  • The deploy section defines the labels on the service, which is the cli option you used. You can also define labels one level up which makes a container label, which is a different cli option. Your syntax looks right for traefik configured for swarm mode. – BMitch Oct 05 '18 at 01:52
  • hey @Marvin did you figure out a way to add the labels? I'm having the same issue – tkyass May 13 '19 at 22:16
  • @tkyass no, never figured it out. I keep doint it in docker-compose – Marvin May 14 '19 at 09:52
  • bummer .. I use stack deploy not compose so I don't know if I still need to place the labels under deploy section in the stack file? – tkyass May 14 '19 at 16:03
  • I use stack deploy as well, with compose file :) – Marvin May 15 '19 at 08:03

1 Answers1

-1

Try --label traefik.enable=“true"

Think you have the quotes in the wrong place

Paul Cochrane
  • 399
  • 1
  • 4