Docker Logs - Tail logs and only show new entries
Many docker containers output log and error information to
/dev/stderr rather than their traditional log files, and you can use the
docker logs command to view those messages. You can make use of the
docker logs command like this:-
docker logs [CONTAINER_ID]
If you want to follow the logs live as you run your application, you can use:-
docker logs --follow [CONTAINER_ID]
By default, the
docker logs command shows all the log entries for that container, and if the container has been running for a while, that can be many lines of output that you are not really interested in. If you are attempting to debug your application, you might want to follow the log entries but beginning now rather than showing everything that came before, i.e. tail the log entries from the end of the log file rather than the start.
You can do this by using
--tail 0 i.e.
docker logs --follow --tail 0 [CONTAINER_ID]
Similarly, if you want to look back over recent entries, you can set the value accordingly, i.e. to view the last 100 entries you can do
docker logs --follow --tail 100 [CONTAINER_ID]
You can also use the shorthand version by replacing
docker logs -f -n 100 [CONTAINER_ID]
Enjoyed this article?
Thank you for reading this article! If you found the information valuable and enjoyed your time here, consider supporting my work by buying me a coffee. Your contribution helps fuel more content like this. Cheers to shared knowledge and caffeine-fueled inspiration!
Originally published at https://chrisshennan.com/blog/docker-logs-tail-from-the-end-of-log-entries