Skip to main content

How do you view container logs?

Container logs are shown with the docker logs command.

1. View the container's logs

bash
docker logs CONTAINER_NAME

or by ID:

bash
docker logs CONTAINER_ID

2. Watch logs in real time (like tail -f)

bash
docker logs -f CONTAINER_NAME

3. Specify the number of last lines

bash
docker logs --tail 50 CONTAINER_NAME

4. View logs with timestamps

bash
docker logs -t CONTAINER_NAME

Summary

TaskCommand
One-time log viewdocker logs NAME
Streaming logsdocker logs -f NAME
Last X linesdocker logs --tail X NAME

Docker shows the container's stdout and stderr - what the application prints to the console.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.