docker logs
The docker logs command is used to fetch the logs of a container. This command retrieves the logs that are generated by the container's main process.
Basic Syntax
Key Options and Parameters
-f, --follow: Follow log output.
docker logs -f mycontainer--since: Show logs since a specific timestamp (e.g., 2023-01-01T00:00:00).
docker logs --since 2023-01-01T00:00:00 mycontainer-t, --timestamps: Show timestamps.
docker logs -t mycontainer--tail: Number of lines to show from the end of the logs (default is all).
docker logs --tail 100 mycontainer--details: Show extra details provided to logs.
docker logs --details mycontainer
Examples
Fetching Logs of a Container
docker logs mycontainerThis command retrieves the logs of the container named
mycontainer.Following Log Output
docker logs -f mycontainerThis command follows the log output of the container named
mycontainer.Showing Logs Since a Specific Timestamp
docker logs --since 2023-01-01T00:00:00 mycontainerThis command shows the logs of the container named
mycontainersince January 1, 2023.Showing Logs with Timestamps
docker logs -t mycontainerThis command shows the logs of the container named
mycontainerwith timestamps.Showing the Last 100 Lines of Logs
docker logs --tail 100 mycontainerThis command shows the last 100 lines of logs of the container named
mycontainer.Showing Extra Details in Logs
docker logs --details mycontainerThis command shows extra details in the logs of the container named
mycontainer.
Conclusion
The docker logs command is essential for retrieving and monitoring the logs of a Docker container. Understanding its options and parameters allows you to effectively manage and debug your Docker containers.