Docker - Tail `docker logs` from the end of the log file

4th May 2022

Many docker containers output log and error information to /dev/stdout and /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]

Liked this article?

Subscribe to my newsletter and get the latest content direct to your inbox