Reputation: 9828
So I noticed that if I docker exec
into an nginx image and go to /var/log/nginx/
that the errors are redirected to stdout
0 lrwxrwxrwx 1 root root 11 Nov 7 00:24 access.log -> /dev/stdout
0 -rw-r--r-- 1 root root 0 Nov 16 04:57 mywebsite_error.log
0 lrwxrwxrwx 1 root root 11 Nov 7 00:24 error.log -> /dev/stderr
I assume this is the output if I use docker logs <nginx-container>
? Does it make sense to also sym link(?) my websites error and access logs to the same output? Would this break the existing links attached to access.log
and error.log
?
Or would a better solution be to simply have my website errors output to those default access and error logs (since only one site will be running on this server)
Upvotes: 2
Views: 9715
Reputation: 9343
The correct solution is situation dependent and up to the designer to determine.
A few options would be:
If you use a log parser to process logs, then combining the rows and using the docker logging drivers is not an issue. The log parser will be able to recognise the log type/source from the log entry itself and handle accordingly. This is straightforward to do for Nginx which writes formatted log entries.
To keep the logs as separate files, mount a host directory as a docker volume where the logs are written and remove the symlinks to stdout/stderr. This provides a predictable way to share the logs outside of the container. This solution may be extended by mounting the logs volume in another container which subsequently processes the logs.
It is also possible to write a script which initiates log shipping tasks such as filebeat from within the container and run in the background. This breaks the microsevice / single process docker convention and therefore is not recommended.
Upvotes: 1
Reputation: 9995
I assume this is the output if I use docker logs ?
Yes.
Does it make sense to also sym link(?) my websites error and access logs to the same output?
It's possible to do that. The error messages would be entangled in all access log entries though.
Would this break the existing links attached to access.log and error.log?
AFAIK no. You can have multiple symlinks to /dev/stdout
.
Upvotes: 3