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

12,433

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

Share:
12,433

Related videos on Youtube

Prashant Prabhakar Singh
Author by

Prashant Prabhakar Singh

Ethereum Developer/ Architect. Mob: +91-9990053172 Email: [email protected] Donation accepted: ETH: 0x6c4465Dc4dC3466c5736142cE8e12917ac1e22C4

Updated on July 09, 2022

Comments

  • Prashant Prabhakar Singh
    Prashant Prabhakar Singh almost 2 years

    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
    Prashant Prabhakar Singh about 7 years
    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
    Prashant Prabhakar Singh about 7 years
    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.
  • Frizlab
    Frizlab about 5 years
    @PrashantPrabhakarSingh This is syslog config, isn’t it?
  • Matias Bello
    Matias Bello over 2 years
    @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