How to view Docker logs?

To view Docker logs for a specific container, you can use the docker logs command. Here’s how to do it:

  1. Identify the Container: First, you need to know the name or ID of the container whose logs you want to view. You can list all running containers with:

    docker ps

    If you want to see all containers (including stopped ones), use:

    docker ps -a
  2. View Logs: Once you have the container name or ID, you can view its logs using the following command:

    docker logs <container_id_or_name>

    Replace <container_id_or_name> with the actual ID or name of your container.

  3. Follow Logs in Real-Time: If you want to view the logs in real-time (similar to tail -f), you can use the -f option:

    docker logs -f <container_id_or_name>
  4. View Specific Number of Lines: If you want to see only the last few lines of the logs, you can use the --tail option:

    docker logs --tail 100 <container_id_or_name>

    This command will show the last 100 lines of logs.

  5. View Logs with Timestamps: To include timestamps in the log output, use the --timestamps option:

    docker logs --timestamps <container_id_or_name>

By using these commands, you can effectively view and monitor the logs of your Docker containers.

0 Comments

no data
Be the first to share your comment!