0
0
Dockerdevops~5 mins

Viewing container logs in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What command shows the logs of a running Docker container?
Use docker logs <container_name_or_id> to see the output and messages from a running container.
Click to reveal answer
beginner
How do you follow the logs in real-time for a Docker container?
Add the -f or --follow option: docker logs -f <container_name_or_id> to watch new log entries as they appear.
Click to reveal answer
intermediate
How can you limit the number of log lines shown from a Docker container?
Use the --tail <number> option, for example: docker logs --tail 10 <container_name_or_id> shows only the last 10 lines.
Click to reveal answer
beginner
What does the docker logs command show by default?
It shows all the logs that the container has produced since it started, including standard output and standard error.
Click to reveal answer
intermediate
Can you view logs of a stopped Docker container?
Yes, docker logs works for stopped containers too, showing the logs they produced before stopping.
Click to reveal answer
Which command shows the logs of a Docker container named 'webapp'?
Adocker logs webapp
Bdocker show logs webapp
Cdocker container logs webapp
Ddocker view logs webapp
How do you watch logs live as they are generated?
Adocker logs --tail 10
Bdocker logs --start
Cdocker logs -f
Ddocker logs --stop
What option limits the number of log lines shown?
A--limit
B--tail
C--head
D--lines
Can you view logs of a container that is not running?
AOnly if you restart the container first
BNo, logs are only available for running containers
COnly if the container was stopped less than 5 minutes ago
DYes, logs are saved and can be viewed anytime
What does the docker logs command show by default?
AAll output since container start
BOnly the last 10 lines
COnly error messages
DOnly logs from the last hour
Explain how to view and follow logs of a Docker container in real-time.
Think about how you watch a live video feed of logs.
You got /4 concepts.
    Describe how to limit the number of log lines shown when viewing Docker container logs.
    Imagine you only want to see the last few messages, not everything.
    You got /4 concepts.