Stack service containers dynamic hostname
Asked Answered
R

1

7

I am migrating away from Docker Cloud to pure Docker Swarm setup. One thing that I am missing is the nice way of how the containers got the hostname set as $SERVICE_NAME-$SLOT_NUMBER.

Is it possible to dynamically set the hostname/container name in a swarm stack service?

Rickety answered 8/4, 2018 at 16:9 Comment(0)
R
10

In your stack/compose file, use this format:

services:
  thaservice:
    ...
    hostname: "{{.Service.Name}}-{{.Task.Slot}}"

Link to documentation for available template variables: https://docs.docker.com/engine/swarm/services/#create-services-using-templates

Rickety answered 8/4, 2018 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.