13

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

Prashant Prabhakar Singh
  • 1,120
  • 4
  • 15
  • 33

1 Answers1

10

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

kstromeiraos
  • 4,659
  • 21
  • 26
  • Thanks.Can't I specify a separate file to store logs on host macine? Like `/var/log/docker/conatiner1.log` and `/var/log/docker/conatiner2.log` ? – Prashant Prabhakar Singh May 10 '17 at 10:32
  • 2
    Thanks for the edit. But that's the default behavior. What if I am using syslog and want to have logs to my custom location. The above path works only if you have not used any logging driver (default), but if you use syslog driver, above location doesn't exist. I am getting logs by using syslog, just I want it to be in a separate file for each container, I want the path and name of the file where logs created to be configurable. – Prashant Prabhakar Singh May 10 '17 at 10:47
  • @PrashantPrabhakarSingh This is syslog config, isn’t it? – Frizlab Mar 13 '19 at 14:29
  • @kstromeiraos i'm using a Linux distribution that does not include syslog by default. Would you please provide me the instructions to add the installation in dockerfile? I've seen this: RUN apt-get -y install rsyslog But it doesn't seem to work. When I look at "/var/log" I don't see any "syslog" folder – Matias Bello Nov 02 '21 at 23:47
  • 1
    @MatiasBello as it mentioned in the answer, you are able to see the log files under `/var/lib/docker/containers/[containerID]/*json.log` or `container-cached.log` even without specifying syslog driver. as default, the log printed when you run the command `docker logs container id`. – Haeyoon J. Jul 12 '22 at 09:23