I need to loop over containers of a service and get the IP addresses of the containers in state running.
So far this is simple. This would be the following template:
{{ with service }}
{{ range .Containers }}
{{ if eq .State "running" }}
IP: {{ .Address }}
{{ end }}
{{ end }}
{{ end }}
But now I need to get only one IP. Ideally the first. And if no container is running, the IP I get should be "127.0.0.1".
Is there a way to do this?
Writing the IPs to a variable inside the iteration does not work, because I do not have access to the variable outside of the iteration.
Hi,
I need to loop over containers of a service and get the IP addresses of the containers in state running. So far this is simple. This would be the following template:
But now I need to get only one IP. Ideally the first. And if no container is running, the IP I get should be "127.0.0.1".
Is there a way to do this? Writing the IPs to a variable inside the iteration does not work, because I do not have access to the variable outside of the iteration.
Regards