====== Docker Logging Drivers ======
===== Alterar log padrão no Docker =====
==== syslog ====
**Driver padrão**:
$ docker system info --format '{{.LoggingDriver}}'
json-file
**Alterando para o driver syslog**:
$ cat /etc/docker/daemon.json
{
"log-driver": "syslog"
}
**Reinicie o Docker para aplicar a alteração**:
sudo systemctl restart docker
**Execute um container para testar**:
docker container run -dit --name web --hostname web httpd
**Vizualise os logs**:
sudo tail /var/log/syslog
Oct 5 20:14:42 dca-manager kernel: [ 2035.958064] IPv6: ADDRCONF(NETDEV_CHANGE): veth69c069d: link becomes ready
Oct 5 20:14:42 dca-manager kernel: [ 2035.958104] docker0: port 1(veth69c069d) entered blocking state
Oct 5 20:14:42 dca-manager kernel: [ 2035.958108] docker0: port 1(veth69c069d) entered forwarding state
Oct 5 20:14:42 dca-manager kernel: [ 2035.958153] IPv6: ADDRCONF(NETDEV_CHANGE): docker0: link becomes ready
Oct 5 20:14:42 dca-manager c79228a3fbf2[1331]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message#015
Oct 5 20:14:42 dca-manager c79228a3fbf2[1331]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message#015
Oct 5 20:14:42 dca-manager c79228a3fbf2[1331]: [Sat Oct 05 20:14:42.042491 2024] [mpm_event:notice] [pid 1:tid 1] AH00489: Apache/2.4.62 (Unix) configured -- resuming normal operations#015
Oct 5 20:14:42 dca-manager c79228a3fbf2[1331]: [Sat Oct 05 20:14:42.042577 2024] [core:notice] [pid 1:tid 1] AH00094: Command line: 'httpd -D FOREGROUND'#015
Oct 5 20:14:43 dca-manager systemd-networkd[547]: veth69c069d: Gained IPv6LL
Oct 5 20:14:43 dca-manager systemd-networkd[547]: docker0: Gained IPv6LL
docker container stop web
web
docker container rm web
web
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
==== Journald ====
docker container run -dit --log-driver=journald --name web --hostname web httpd
d8f4563f67abff86be2a2fe651598e127767ef8d7285e126c937e5b3914a0b1a
docker container logs web
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sat Oct 05 20:21:59.601065 2024] [mpm_event:notice] [pid 1:tid 1] AH00489: Apache/2.4.62 (Unix) configured -- resuming normal operations
[Sat Oct 05 20:21:59.601160 2024] [core:notice] [pid 1:tid 1] AH00094: Command line: 'httpd -D FOREGROUND'
**Para acompanhar os logs**:
sudo journalctl --output=cat CONTAINER_NAME=web
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this mes>
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this mes>
[Sat Oct 05 20:21:59.601065 2024] [mpm_event:notice] [pid 1:tid 1] AH00489: Apache/2.4.62 (Unix) configured -- resuming normal operations
[Sat Oct 05 20:21:59.601160 2024] [core:notice] [pid 1:tid 1] AH00094: Command line: 'httpd -D FOREGROUND'
docker container stop web
web
docker container rm web
web