How do you view log files in Docker?

To view the log files of a Docker container, you can use the docker logs command. Here are the steps to view container log files using the docker logs command:

  1. Firstly, use the following command to check the ID or name of the running Docker container:
  2. list all running containers
  3. Copy or make note of the ID or name of the container you want to view the log files for.
  4. Execute the following command to view the log file of this container:
  5. Display logs for a specific container by using either the container ID or name.
  6. For example, to view the logs of a container named my_container, run the following command:
  7. Show me the logs of my container in Docker.
  8. By default, this command will display all the log content of the container.
  9. To track real-time log output, you can use the -f option.
  10. Follow the logs of the container with the specified ID or name.
  11. This will display the real-time logs of the container and continuously update whenever new logs are outputted.

Note: If the container has already stopped running, you can specify the time range of logs to view by adding the –since and –until options. For example, to view logs from the past 10 minutes, you can run the following command:

docker logs --since 10m <容器ID或名称>

This way, you can use the docker logs command to view the log files of the Docker container.

bannerAds