HansElsen
HansElsen

Reputation: 1753

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

Upvotes: 4

Views: 5905

Answers (2)

HansElsen
HansElsen

Reputation: 1753

I found it. Apparently you can write logs from docker containers via

RUN ln -sf /proc/1/fd/1 /opt/myserver/logs/server.log

in your Dockerfile

Upvotes: 2

Jan Garaj
Jan Garaj

Reputation: 28716

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

Upvotes: 4

Related Questions