Docker Community Forums

Share and learn in the Docker community.

Swarm: Task.Slot as runtime container label

docker
swarm

(Zarnovican) #1

Hi,

I’m trying to get the value of .Task.Slot into a container label (in Swarm).

This does not work (template variables are not expanded in label values):

  redis:
    image: redis
    labels:
      foo: "{{.Task.Slot}}"

There are existing labels, which contain that value (“3”) as a substring (docker.swarm.task.name=redis.3.fwgp1aipl82s86up9vyiidw5e). In my use-case, I’m not able to parse it out. I would like to have a label which contain just the task slot.

Use-case:
I’m monitoring containers via Telegraf. I would like to use Service.Name+Task.Slot as unique identifier for the series. If I use existing unique label (for example docker.swarm.task.name), Telegraf will create a new time-series every time someone makes a deploy.

It would be really ideal, if Swarm containers already had a label like that (com.docker.swarm.task.slot ?).

Any suggestions ?

BranoZ


(Junius) #2

You may try “-e TASK_SLOT={{.Task.Slot}}” when creating the service.