The situation is as follows:
- The spring-boot service writes logs via logback to the output.log file
- Logback is configured to rotate logs and it periodically empties output.log, dropping logs into archive files specified in the rotation policy. That is, the output.log itself is such a temporary buffer with the most recent log
- That all works fine: https://www.youtube.com/watch?v=hrWmfC3y9zM
- But if we mount the logs folder from the container outside to the host volume (and we need this for reading with a third-party utility), then everything breaks down: output.log stops being automatically cleared, grows indefinitely, and the archive files specified in the rotation policy are not created at all. This happens even when no one reads the file from this directory on the host machine.
For example
1) Directories inside container:
/app/
|-> service.jar
the buffer log is written here:
/app/logs/
|-> output.log
rotated archive log files are stored here
/app/
| -> out1.log
| -> out2.log
directory is mounted to the host in docker compose:
volumes:
- /LOGS:/app/logs:rw
2. The second container reading logs is mounted like this:
volumes:
- /LOGS:/var/log
But even when reading container is stopped, the file is locked. Just mounting folder from the source container is enough for blocking
Is this some kind of feature of docker volumes? Has it some workaround?