Docker- How to use syslog to record logs on host machine?

Prashant Prabhakar Singh picture Prashant Prabhakar Singh · May 10, 2017 · Viewed 9.9k times · Source

I wish to keeps the logs of my container to a file in my host machine for every container. I read about doing the same via logging driver.

Since my host machine runs ubuntu 14.04, which has rsyslog running by default, I thought to use syslog.

What I did was used following command to run the container:

docker run -it --log-driver=syslog --log-opt syslog-address=udp://localhost:514 prashant23/ubuntu-java:sample-jdbc-project bash

and I went inside the container without any error. That's all? How do I know that where I can see logs on my host machine? Did I do everything right? I have no idea about syslog. Do I need to configure syslog on my container too? Is there any better approach to achieving the same.

I am not sure what should I use as syslog-address. From where I can get the value of this parameter? I somewhere read default is udp://localhost:514

Answer

kstromeiraos picture kstromeiraos · May 10, 2017

Using syslog driver, your Docker container will write log data to /var/log/syslog file. You should find your container logs in that file.

syslog-address is only needed if you use an external syslog server, which doesn't seem to be your case.

Using default driver json-file, Docker will create a log file in this path.

/var/lib/docker/containers/[container-id]/[container-id]-json.log