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_NAMEor by ID:
bash
docker logs CONTAINER_ID2. Watch logs in real time (like tail -f)
bash
docker logs -f CONTAINER_NAME3. Specify the number of last lines
bash
docker logs --tail 50 CONTAINER_NAME4. View logs with timestamps
bash
docker logs -t CONTAINER_NAMESummary
| Task | Command |
|---|---|
| One-time log view | docker logs NAME |
| Streaming logs | docker logs -f NAME |
| Last X lines | docker logs --tail X NAME |
Docker shows the container's stdout and stderr - what the application prints to the console.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.