Logs are essential for troubleshooting any issues encountered during the software development and delivery process. Docker also provides several logging options to aid in the troubleshooting experience. This blog discusses various ways to review log files with Docker
Pre-requisites:
1. --tail
This option limits the number of log lines displayed when retrieving Docker logs. It is useful when analyzing a long log with many lines and it allows users to view the most recent log entries from the end of the logs.
docker logs CONTAINER ID --details --tail NUMBER OF LINES
2. -f or --follow
This option is used to continuously stream logs to the terminal in real-time. It allows us to see new log entries as they are created. This command is very helpful in situations such as container trying to access another service or containers, such as databases and experiencing connection issues. It provides live logs, showing what is really happening when trying to access the database by the application running inside the docker.
The following example shows logs generated by a Weather forecast app running in docker which is accessible via port 8080.
docker logs CONTAINER ID --follow
The weatherforecast GET endpoint was executed to generate new logs
After running the GET /weatherforecast endpoint, the following logs were generated in real-time
No comments:
Post a Comment