Home  >  Article  >  Operation and Maintenance  >  Where are docker logs saved?

Where are docker logs saved?

PHPz
PHPzOriginal
2023-04-20 10:07:541695browse

Docker is an open source containerization platform that allows developers to run applications in containers. When running a container, Docker records container-related logs, including all events when the container starts, runs, and stops.

Docker outputs all logs to the container's stdout and stderr by default, and these logs can be easily accessed and searched through the docker logs command. The syntax of the docker logs command is as follows:

docker logs [OPTIONS] CONTAINER

Among them, OPTIONS is optional and can include the following parameters:

  • --details: Display detailed log information
  • --follow, -f: Follow the log output, even if the container has stopped
  • --since: Output the log after the specified time, you can use the timestamp in ISO 8601 format, or you can use relative time, such as 2 hours Front
  • --tail: Output the last N lines of logs, the default is all logs
  • --timestamps, -t: Include timestamps in the log output

CONTAINER is the name or ID of the container to obtain log information.

However, Docker logs are not just saved in the container, they are actually saved on the host machine. Specifically, Docker saves the container's log information in a JSON file, which is located in the host's /var/lib/docker/containers/[CONTAINER ID]/[CONTAINER ID]-json.log path, where [CONTAINER ID ] is the ID number of the container.

So, if you want to check the log file of a Docker container, just log in to the host machine and navigate to the relevant path. You can use tools such as cat or tail to view the contents of the log file. In addition, there are some third-party tools that can help you manage and analyze Docker logs more easily, such as ELK log analysis suite and Fluentd, etc.

Overall, Docker logs are a very important resource that can help you diagnose and solve container-related issues. Understanding the basics of Docker logs and obtaining guidance are essential skills for managing Docker containers and are highly recommended.

The above is the detailed content of Where are docker logs saved?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn