How to send logs to Graylog (Docker)?

Shamik Mukherjee picture Shamik Mukherjee · Aug 3, 2016 · Viewed 11.4k times · Source

I'm new to both Docker and Graylog. Can anyone show me an example of how to send log data to the Graylog server?

Answer

Paul Weber picture Paul Weber · Aug 4, 2016

Actually, it is pretty easy! Graylog's preferred Log Format - GELF - is supported by Docker natively. So if you are using Docker logs already (Docker's internal logging functionality) you can just use Docker's built-in support, that will forward all logs from your container to the specified GELF endpoint. You will have to create a GELF UDP input on the Graylog server.

https://docs.docker.com/engine/admin/logging/overview/

For running a container from command line that sends all logs to Graylog via GELF just use the options log-driver and gelf-address:

docker run -dit \
--log-driver=gelf \
--log-opt gelf-address=udp://192.168.0.42:12201 \
alpine sh