If you use the Coreutils tail command in Linux, you have a -f option that lets you follow a log file from the log's current position (it does not go to the very beginning of the file and display everything).
Is this functionality available in docker logs without waiting for it to traverse the whole log?
I have tried:
docker logs --since 1m somecontainer
and
docker logs -f --since 1m somecontainer
It appears that it actually traverses the entire log file (which can take a long time) and then starts echoing to the screen once it reaches the time frame you specify.
Is there a way to start tailing from the current point without waiting? Is my best option to always log out to some external file and tail that with the Coreutils tail command?
As you've seen, Docker provides multiple CLI options to display logs in different formats. For example, you can display logs for a specified point in time. In addition, the follow option is one of the most used Docker options because it allows developers to live tail logs for specific containers.
You find these JSON log files in the /var/lib/docker/containers/ directory on a Linux Docker host. The <container_id> here is the id of the running container. If you're not sure which id is related to which container, you can run the docker ps command to list all running containers.
Using Default Log File By default, Docker stores log files in a dedicated directory on the host using the json-file log driver. The log file directory is /var/lib/docker/containers/<container_id> on the host where the container is running.
Please read docker logs --help
for help. Try below, starting from the last 10 lines. More details here.
docker logs -f --tail 10 container_name
Alternatively, we can check the log by time (eg. since last 2mins) as:
docker logs --since=2m <container_id> // since last 2 minutes
docker logs --since=1h <container_id> // since last 1 hour
use the --tail switch:
> docker logs -f <container name> --tail 10
this will show the log starting from the last 10 lines onwards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With