docker-gen icon indicating copy to clipboard operation
docker-gen copied to clipboard

NetworkSettings > IPAddress is sometimes "" in docker inspect, seems to cause empty address entry in Addresses

Open ghost opened this issue 8 years ago • 4 comments

NetworkSettings > IPAddress is sometimes "" in docker inspect, which seems to cause empty address entry in docker-gen's supplied Addresses property which makes my templates yield empty addresses as targets. In all cases the container DOES actually have an IP, but it's only shown inside NetworkSettings > Networks > bridge > IPAddress.

I'm not sure if this is something docker shouldn't do or an unavoidable new thing with docker's new networking tools... however:

  1. I don't use any special network settings at all. Everything uses the default network
  2. Still, this happens and my templates break...

See https://github.com/docker/docker/issues/21658 for more details.

Since I have no idea on which side the problem cause is, I thought I might as well also add a ticket here to give you a chance of adding your thoughts

ghost avatar Mar 30 '16 16:03 ghost

I got the same when using docker-compose version 2 networking, pls patch docker-gen for this ! 👍

nox-404 avatar Jun 05 '16 14:06 nox-404

I confirm it happens on docker-compose version 2 configs.

Is there a way to manually set it in the compose file?

TopperH avatar Jun 14 '16 14:06 TopperH

Pretty late to the game but hope this might be useful to others. Took a long time for me to get this running but it is working now for my use case. Had to fish through the source code (generator.go , from line 382 onwards more specifically) to get at what container properties docker-gen is looking at and what variable names they map to.

I can confirm that IP Address is always blank for me. I am using this in the 2 container version of jwilder/nginx-proxy. I followed the code examples with the below changes.

Changed 'Addresses' {{ range $index, $value := $containers }} {{ with $address := index $value.Addresses 0 }} server {{ $address.IP }}:{{ $address.Port }}; {{ end }} {{ end }}

to 'Networks'

{{ range $index, $value := $containers }} {{ with $address := index $value.Networks 0 }} server {{ $address.IP }}; {{ end }} {{ end }}

Please note that I didn't see port information with this change. In my case it is port 80 so I'm not specifying, but that might be an issue for others.

botwhytho avatar Apr 28 '17 08:04 botwhytho

Even later to the game, but I just had this issue. Seems when we define a custom network then there will be no IP address in the place where it's being retrieved. @botwhytho already helped with how to get the IP address, but the port can also be retrieved using the old way. I solved it this way:

{{ range $index, $value := $containers }}
    {{ with $port := index $value.Addresses 0 }}
        {{ with $address := index $value.Networks 0 }}
            server {{ $address.IP }}:{{ $port.Port }};
        {{ end }}
    {{ end }}
{{ end }}

So I just take the port like previously, but the IP address from the Networks section. This way you can get both.

Symbiatch avatar Feb 11 '21 08:02 Symbiatch