📜  docker logs - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:40:49.321000             🧑  作者: Mango

Docker Logs - Shell/Bash

Introduction

Docker Logs is a useful command-line tool for viewing logs generated by Docker containers. It allows developers and system administrators to track the output and debugging information produced by containerized applications. By monitoring logs, you can easily troubleshoot issues, analyze container behavior, and gain insight into the application's runtime activities.

Usage

The basic usage of the docker logs command is as follows:

docker logs [OPTIONS] CONTAINER
Options

Here are some commonly used options for the docker logs command:

  • -f, --follow: This option enables real-time log streaming. It continuously displays new log output as it is generated.
  • --tail: Use this option to view only a specific number of lines from the end of the logs. For example, --tail 100 will display the last 100 lines.
  • --since: View logs since a specified timestamp. You can provide a relative time like 10m for the past 10 minutes or an absolute time in the format YYYY-MM-DDTHH:MM:SS.
  • --until: View logs until a specified timestamp. Similar to --since, you can provide relative or absolute timestamps.
Examples
  1. Display logs for a running container:
docker logs my-container
  1. Stream and display logs in real-time:
docker logs -f my-container
  1. View the last 50 lines of container logs:
docker logs --tail 50 my-container
  1. Display logs since a specific timestamp:
docker logs --since 2021-01-01T00:00:00 my-container
  1. Display logs for a specific time range:
docker logs --since 2021-01-01T00:00:00 --until 2021-01-02T00:00:00 my-container
Markdown Code Formatting

To format code snippets in Markdown, you can use triple backticks (```) with the appropriate language identifier. For example:

```bash
docker logs my-container

This renders as:

```bash
docker logs my-container

Make sure to replace the language identifier, bash in this case, with the relevant language for your code snippet.