The outcomes of this guide are:
- What is Docker Tail Logs?
- How to Tail Docker Logs to See Recent Records, Not All?
- How to Tail Docker Logs to See Recent Records by Providing the Specific Time?
What is “docker logs –tail”?
In Docker, the docker logs tail command is used to check the Docker container logs in real time and provide a continuous stream of log outputs. This command is also utilized for managing the containers and quick troubleshooting.
How to Tail Docker Logs to See Recent Records, Not All?
To display the most recent log history of any Docker container, first, get the container ID by running the provided command:
From the given output, we have copied the below highlighted container ID for further process:
Then, execute the following command to tail the Docker container log for displaying the most recent history:
Here:
- Docker logs command is used to retrieve logs that exist at the time of the execution.
- –follow option is used to continue streaming the new output from the containers.
- –tail tag is used to specify the required number of lines to show from the end of the logs.
- 10 is the desired number of logs that we want to show on the terminal.
- C7ccd4b…. is our container id:
The above-provided can be executed to tail Docker logs for displaying the most recent records using the short form of the option. For instance, the –follow as -f and –tail as -n:
How to Tail Docker Logs to See Recent Records by Providing the Specific Time?
We can also get the most recent logs of the Docker containers by providing the specific time duration. For that purpose, check out the below-stated command where we used the –since option that takes the 50m as its value:
That’s it! We have illustrated the process to tail Docker logs for displaying the recent records.
Conclusion
To tail the Docker logs for displaying the most recent records on the terminal, the docker logs –follow –tail <num-lines> <container-id> command is used. The –tail option is utilized for viewing a specific number of tail logs. This blog has demonstrated the method to tail Docker logs for viewing recent records.