0

I'm looking at wurstmeister/kafka-docker, and found this pull suggesting using the IP address. Basically, it uses the docker info formatting:

HOSTNAME_COMMAND: "docker info -f '{{`{{.Swarm.NodeAddr}}`}}'"

I get the idea that it uses the formatting to get the address, but I don't understand what's going on with the extra {{...}} and the backticks (which would normally be an eval). docker-compose allows for ${variables}, but there's no dollar sign ($) here, so no need to escape. Why isn't this just:

HOSTNAME_COMMAND: "docker info -f '{{.Swarm.NodeAddr}}'"

I've seen this elsewhere, so I assume there's a reason.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
mconner
  • 1,174
  • 3
  • 12
  • 24

1 Answers1

0

This is basically a duplicate of this post. However, you might not find that one if you aren't aware that docker-compose files use Go templates (I didn't find any mention of it in the compose file reference). So basically, in go, the backquotes indicate a literal string, so the outer set of {{ }} is a template allowing for the backquotes to take everything between literally.

mconner
  • 1,174
  • 3
  • 12
  • 24