Docker: Symlink your log files to stdout and stderr!

When you’re in a Docker container, ideally you don’t want to have to enter the container in order to read log files. It’d be best to have everything on stdout and stderr of your container so Docker picks them up automatically and thus delivers it to any logging driver you attach.

This is thankfully easily achieved by symlinking your logfiles to stdout and stderr like, for example, nginx does in their Dockerfile:

RUN ln -sf /dev/stdout /var/log/nginx/access.log \
	&& ln -sf /dev/stderr /var/log/nginx/error.log

This will make all writes to access and error log visible on the container’s output and, thus, in your Docker logs so it can be picked up by any logging driver.