In Docker, you can usedocker logs
Command to view the container's log. Here are some common uses:
Basic usage
docker logs <container_id_or_name>
: View the standard output (stdout) and standard error (stderr) logs of the specified container.
View logs in real time
docker logs -f <container_id_or_name>
: Real-time tracking log output (similar totail -f
)。
View the recent logs
docker logs --tail <number_of_lines> <container_id_or_name>
: View the log of the most recent specified number of rows. For example, view the most recent 100-line log:
docker logs --tail 100 <container_id_or_name>
View logs for specific time ranges
docker logs --since <timestamp> <container_id_or_name>
: View logs after the specified time point. The timestamp can be in date format or relative time (e.g.1h
Indicates the past hour).
docker logs --since "2023-05-01T00:00:00" <container_id_or_name> docker logs --since 1h <container_id_or_name>
docker logs --until <timestamp> <container_id_or_name>
: View the log before the specified time point.
docker logs --until "2023-05-01T00:00:00" <container_id_or_name> docker logs --until 1h <container_id_or_name>
Combination use
-
docker logs -f --tail 100 <container_id_or_name>
: Track the logs in real time and display only the most recent 100 rows. -
docker logs --since 1h --until 30m <container_id_or_name>
: View logs from the past hour to the past 30 minutes.
Example
Suppose you have a container ID ofabc123
, you can use the following command to view its log:
View all logs:
docker logs abc123
View the log in real time:
docker logs -f abc123
View the most recent 50-line log:
docker logs --tail 50 abc123
Check out the logs for the past hour:
docker logs --since 1h abc123
View logs from a specific point in time:
docker logs --since "2023-05-01T00:00:00" abc123
With these commands, you can easily view and track the logs of Docker containers, helping you debug and monitor.
This is the article about the implementation steps of docker log check command. For more related docker log check command content, please search for my previous article or continue browsing the related articles below. I hope everyone will support me in the future!