AICollection Help

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

docker logs [OPTIONS] CONTAINER

Key Options and Parameters

  1. -f, --follow: Follow log output.

    docker logs -f mycontainer
  2. --since: Show logs since a specific timestamp (e.g., 2023-01-01T00:00:00).

    docker logs --since 2023-01-01T00:00:00 mycontainer
  3. -t, --timestamps: Show timestamps.

    docker logs -t mycontainer
  4. --tail: Number of lines to show from the end of the logs (default is all).

    docker logs --tail 100 mycontainer
  5. --details: Show extra details provided to logs.

    docker logs --details mycontainer

Examples

  1. Fetching Logs of a Container

    docker logs mycontainer

    This command retrieves the logs of the container named mycontainer.

  2. Following Log Output

    docker logs -f mycontainer

    This command follows the log output of the container named mycontainer.

  3. Showing Logs Since a Specific Timestamp

    docker logs --since 2023-01-01T00:00:00 mycontainer

    This command shows the logs of the container named mycontainer since January 1, 2023.

  4. Showing Logs with Timestamps

    docker logs -t mycontainer

    This command shows the logs of the container named mycontainer with timestamps.

  5. Showing the Last 100 Lines of Logs

    docker logs --tail 100 mycontainer

    This command shows the last 100 lines of logs of the container named mycontainer.

  6. Showing Extra Details in Logs

    docker logs --details mycontainer

    This 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.

Last modified: 05 December 2024