I have unit tests running on my build server and would like to capture the log results for analysis when something fails. I have yet to find a way to redirect the output of
The solution I made is based on Chris McKinnel's answer with some enhancements.
I needed to dump last 1MIO records from my nginx container and docker-compose logs --tail 1000000 nginx > last1mio.log
was too slow and the output was not exactly the same as usual nginx files have.
This is solution that works for me:
docker inspect --format='{{.LogPath}}' nginx-1 \
| xargs tail -n 1000000 \
| jq -r -j .log > last1mio.log 2>&1
Notes:
nginx-1
- I use docker-compose option container_name:
for having this constant In my case dump of last 1mio lines of nginx log takes cca 10s.