nginx-proxy / docker-gen

Generate files from docker container meta-data
MIT License
4.44k stars 604 forks source link

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

Open ghost opened 8 years ago

ghost commented 8 years ago

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

Nox-404 commented 8 years ago

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

TopperH commented 8 years ago

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

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

botwhytho commented 7 years ago

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.

Symbiatch commented 3 years ago

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.