Using links in log options: No such host

Hi fellow Dockerteers,

Apologies if this has been asked before.

I’m trying to use the Gelf log driver to send data from a container to a linked Logstash instance living on the same server. However, when I do that the engine sends the following error that indicates the link is not known: “Failed to initialize logging driver: gelf: cannot connect to GELF endpoint: logstash:12201 dial udp: lookup logstash: no such host”

A simple test that demonstrates this is encapsulated in this docker-compose.yml:

apache:
image: httpd
ports:
- "80:80"
links:
- "logstash:logstash"
log_driver: "gelf"
log_opt:
gelf-address: "udp://logstash:12201"

logstash:
image: logstash
ports:
- "12201:12201"
- "12201:12201/udp"
volumes:
- ./conf:/conf
command: logstash -f /conf/gelf.conf

However, if I specify the server name in the gelf-address everything works fine, but this breaks the portability of the composition.

Is this a bug or gotcha or am I doing something wrong? (The smart money’s on the latter)

Thanks,

Matt

As a followup, I tried abandoning the link idea and using a weave network. Although I could get the apache container to ping the logstash container, the plugin threw the same error.

Any help or guidance would be appreciated.

For any who may be interested, I found a solution, and it’s mind-bogglingly simple.

As it turns out (and is quite obvious in retrospect), the GELF log driver doesn’t use its container’s network stack; it uses the host’s. I haven’t tested the other drivers, but it may be the case with them as well.

As such, “localhost” can be used to refer to the running host in the log options: replacing reference to the “logstash” container with “localhost” in the gelf-address did the trick.

I hope this helps somebody.

Cheers,

Matt

Thanks. It helped. Adding related issues:
20370
2657

Cannot paste direct link due to some silly restrictions…

1 Like