Many of you know that it’s possible to access Docker container logs using “docker logs” command. But fewer people know that it’s possible to follow logs stream for new messages (like tail -f), and even fewer yet are aware that it’s possible to specify timestamps of the period you want to review – showing only specific logs during that period.
Show Docker Container Logs
Easiest command is this:
This will show you all the available logs for the mycontainer1, showing most recent logs last.
Following Docker Container Logs
To follow Docker container for new logs that happen after you start the command, use -f option (f for follow) – like this:
Initially output won’t be very different from the first example, without -f. But you won’t get command line prompt and if you wait long enough, new log messages will start appearing.
Docker Logs Around Certain Time
This is a true gem – using these options allows you not only to focus on specific time period, but also to automatically extract only certain logs based on their timestamps.
NOTE: It’s possible to specify proper timestamps – meaning both date and time, but I find that just the date part is more than enough.
For timestamp based logs access, use the –since and –until options of the docker logs command.
Here’s an example of looking at a Java based container, as you can see only the messages from March 30th and until April 1st are shown: