Sponsored By: Password Angel - Share passwords, API keys, credentials and more with secure, single-use links.

Docker Logs - Tail logs and only show new entries

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]

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

docker logs -f -n 100 [CONTAINER_ID]

Liked this article?

Subscribe to my newsletter and get the ramblings of a wannabe #indiehacker straight in your inbox once a month. Ramblings will cover a variety of topics including:-

Web Development, DevOps, Startups, Bootstrapping, #buildinpublic, SEO, opinion and personal experience.

I won't send you spam and you can unsubscribe at any time.