DEV Community

Chris Shennan
Chris Shennan

Posted on • Updated on • Originally published at chrisshennan.com

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

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]
Enter fullscreen mode Exit fullscreen mode

If you want to follow the logs live as you run your application, you can use:-

docker logs --follow [CONTAINER_ID]
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

You can also use the shorthand version by replacing --follow with -f and --tail with -n like

docker logs -f -n 100 [CONTAINER_ID]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)