To view Docker logs for a specific container, you can use the docker logs command. Here’s how to do it:
-
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 psIf you want to see all containers (including stopped ones), use:
docker ps -a -
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. -
Follow Logs in Real-Time: If you want to view the logs in real-time (similar to
tail -f), you can use the-foption:docker logs -f <container_id_or_name> -
View Specific Number of Lines: If you want to see only the last few lines of the logs, you can use the
--tailoption:docker logs --tail 100 <container_id_or_name>This command will show the last 100 lines of logs.
-
View Logs with Timestamps: To include timestamps in the log output, use the
--timestampsoption:docker logs --timestamps <container_id_or_name>
By using these commands, you can effectively view and monitor the logs of your Docker containers.
