Search code examples
dockergraylog2

Redirect python print output to graylog2


What I'm trying to achieve is to redirect python print from one docker container to the other (without any modification inside python code), with graylog2 (I'm currently using older version, all in one).

So my first docker instance contains graylog server. I created second instance with Dockerfile, using Ubuntu and included simple script that prints current time:

from datetime import datetime
import time

date = datetime.now()
print(str(date.day) + '/' + str(date.month) + '/' + str(date.year))
while True:
   date = datetime.now()
   print(str(date.hour) + ':' + str(date.minute) + ':' + str(date.second))
   time.sleep(1)

I'm using command below to start graylog

docker run -t -p 9000:9000 -p 12201:12201 graylog2/allinone

and to start second container and run my script:

docker run --log-driver=gelf --log-opt gelf-address=udp://0.0.0.0:12201 test python -i ../test.py

I'm trying to send my logs to GELF UDP, not sure if it's the right way, because there are no logs whatsoever, no matter which address/port I choose. For now I can't even log simple echo from bash, but I'm not sure where's the problem itself.


Solution

  • You must bind udp port for graylog2 container.

    docker run -t -p 9000:9000 -p 12201:12201/udp graylog2/allinone