Docker includes multiple logging mechanisms to help you get information from running containers and services. These mechanisms are called logging drivers. Each Docker daemon has a default logging driver, which each container uses unless you configure it to use a different logging driver, or “log-driver” for short.
STEPS :-
Configure Docker to user Syslog
- vim /etc/rsyslog.conf
In the file editor, uncomment the two lines under `Provides UDP syslog reception` by removing `#`.
#ModLoad imudp
#UDPServerRun 514
Then
systemctl start rsyslog
- Now that syslog is running, let’s configure Docker to use syslog as the default logging driver. We’ll do this by creating a file called daemon.json
sudo mkdir /etc/docker
vi /etc/docker/daemon.json
{ "log-driver":
"syslog",
"log-opts": {
"syslog-address": "udp://<PRIVATE_IP>:514" }
}
Then
systemctl start docker
Time to use for docker
For example , first method
docker container run -d --name syslog-logging httpd
Check by
docker logs syslog-logging
Or
tail /var/log/messages
second way to use the enable logging
docker container run -d --name json-logging --log-driver json-file httpd
Check
docker logs json-logging
Docker power 👌
Enjoy
Osama