0
0
Dockerdevops~20 mins

Viewing container logs in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Log Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Viewing logs of a running container
You have a Docker container named webapp running. Which command shows the logs of this container?
Adocker logs webapp
Bdocker show logs webapp
Cdocker container logs webapp
Ddocker get logs webapp
Attempts:
2 left
💡 Hint
The command to see logs starts with docker logs.
💻 Command Output
intermediate
2:00remaining
Viewing real-time logs with follow option
You want to see live logs from a container named db as they are generated. Which command will do this?
Adocker logs db -r
Bdocker logs --tail=0 db
Cdocker logs -f db
Ddocker logs db --live
Attempts:
2 left
💡 Hint
The option to follow logs live is a single letter.
Configuration
advanced
2:00remaining
Limiting log output to recent lines
You want to see only the last 50 lines of logs from a container named api-server. Which command achieves this?
Adocker logs -n 50 api-server
Bdocker logs --tail 50 api-server
Cdocker logs --last 50 api-server
Ddocker logs api-server --limit 50
Attempts:
2 left
💡 Hint
The option to limit lines is --tail.
Troubleshoot
advanced
2:00remaining
Error when viewing logs of a stopped container
You run docker logs myapp but get the error: Error: No such container: myapp. What is the most likely cause?
AYou must use <code>docker logs -a myapp</code> to see logs of stopped containers
BYou need to add <code>-f</code> option to see logs
CDocker daemon is not running
DThe container named <code>myapp</code> does not exist or was removed
Attempts:
2 left
💡 Hint
Check if the container is listed with docker ps -a.
Best Practice
expert
3:00remaining
Efficiently managing large container logs
Your container produces very large logs. Which approach is best to avoid filling disk space while still being able to view recent logs?
AConfigure Docker logging driver to use log rotation with size limits
BManually delete log files in /var/lib/docker/containers regularly
CUse <code>docker logs --tail 10</code> every time to limit output
DStop the container frequently to clear logs
Attempts:
2 left
💡 Hint
Docker supports built-in log rotation settings.