Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify log file for docker container

I have this set of services I wish to do some logging for. Some services are running a node app, so the output is directly visible in the docker logs command.
However, a couple are different. Let's use my Java application as an example. It's running in a wrapper but the logging is written to a log file instead of STDOUT.

How can I hook the file as the docker logs output?

ps. The other app is an PHP app on a Nginx server, also with it's own logging file.

-UPDATE
The application is a Java application (.jar file) running in Java Service Wrapper from Tanuki. The built JAR has a Log4j logger writing via a DailyRollingFileAppender to logs/server.log. The Wrapper itself has output which I ignore via >/dev/null 2>&1. I just added to following line to the Dockerfile.

RUN ln -sf /dev/stdout /opt/myserver/logs/server.log

This is not working though. No output is send when I use docker-compose up myserver

like image 907
HansElsen Avatar asked Oct 16 '25 03:10

HansElsen


1 Answers

Link log file(s) to stdout/stderr. For example in your Dockerfile:

RUN ln -sf /dev/stdout /<path>/logfile.log \
    && ln -sf /dev/stderr /<path>/errors-logfile.log
like image 168
Jan Garaj Avatar answered Oct 17 '25 16:10

Jan Garaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!