I am deploying a Nginx container and in the standard Dockerfile logs are being redirected to container logs with these commands
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
If I remove above mentioned commands then logs are written to access.log and error.log files as expected.
How can I keep the logs in the files as well as send them to container logs ?
1- The below command does not redirect the content of
/var/log/nginx/access.logto/dev/stdoutinstead it created a symlink from/dev/stdoutto/var/log/nginx/access.log. In other words,/var/log/nginx/access.logis just a symlink.2- Storing files in the docker containers is not recommended at all for two reasons. First, the files will be lost once the containers are recreated. Second, the files could grow to huge sizes especially if there is not log rotation over these files. Instead of keeping a copy inside the container you can use FluentD or configure docker itself to forward the logs to an external server or a file on the host node.