Bird
Raised Fist0
Dockerdevops~20 mins

Viewing container logs in Docker - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What does the command docker logs CONTAINER do?
easy
A. Starts a new container
B. Deletes the specified container
C. Shows the logs of the specified container
D. Lists all running containers

Solution

  1. Step 1: Understand the command purpose

    The command docker logs is used to view the output logs of a container.
  2. Step 2: Identify the correct action

    Since it shows logs, it helps to see what the container is doing or any errors it has.
  3. Final Answer:

    Shows the logs of the specified container -> Option C
  4. Quick Check:

    docker logs = show container logs [OK]
Hint: Logs show container output; use docker logs CONTAINER [OK]
Common Mistakes:
  • Confusing logs with starting or deleting containers
  • Thinking it lists containers instead of showing logs
2. Which of these is the correct syntax to follow live logs of a container named webapp?
easy
A. docker logs webapp -p
B. docker logs -f webapp
C. docker logs --tail webapp
D. docker logs webapp --start

Solution

  1. Step 1: Identify the option to follow logs live

    The -f flag means "follow" and shows logs as they appear in real time.
  2. Step 2: Check the syntax correctness

    The correct syntax is docker logs -f webapp. Other options are invalid or incorrect.
  3. Final Answer:

    docker logs -f webapp -> Option B
  4. Quick Check:

    -f means follow logs live [OK]
Hint: Use -f to follow logs live as they update [OK]
Common Mistakes:
  • Using --tail without a number to follow logs
  • Adding invalid flags like --start or -p
  • Placing flags after container name incorrectly
3. What will be the output of the command docker logs --tail 3 mycontainer if the container's last 5 log lines are:
Line1
Line2
Line3
Line4
Line5
medium
A. Line3 Line4 Line5
B. Line1 Line2 Line3
C. Line4 Line5
D. Line1 Line2 Line3 Line4 Line5

Solution

  1. Step 1: Understand the --tail option

    The --tail 3 option shows only the last 3 lines of the logs.
  2. Step 2: Select the last 3 lines from the given logs

    The last 3 lines are Line3, Line4, and Line5.
  3. Final Answer:

    Line3 Line4 Line5 -> Option A
  4. Quick Check:

    --tail 3 shows last 3 lines [OK]
Hint: --tail N shows last N lines of logs [OK]
Common Mistakes:
  • Choosing first lines instead of last lines
  • Confusing --tail with -f
  • Expecting all logs instead of limited lines
4. You run docker logs -f myapp but see no output even though the app is running. What is the likely problem?
medium
A. You need to restart Docker daemon
B. The -f flag is not supported
C. Logs are disabled by default
D. The container name is incorrect or not running

Solution

  1. Step 1: Check container status and name

    If the container name is wrong or the container is stopped, no logs will appear.
  2. Step 2: Understand the -f flag behavior

    The -f flag follows logs live, but if no logs exist or container is not running, output is empty.
  3. Final Answer:

    The container name is incorrect or not running -> Option D
  4. Quick Check:

    No logs means container name or status issue [OK]
Hint: Check container name and running status first [OK]
Common Mistakes:
  • Assuming -f flag is unsupported
  • Thinking logs are disabled by default
  • Restarting Docker unnecessarily
5. You want to see only the last 10 lines of logs from a container named dbserver and keep watching new logs as they appear. Which command should you use?
hard
A. All of the above
B. docker logs -f --tail 10 dbserver
C. docker logs --tail=10 -f dbserver
D. docker logs --tail 10 -f dbserver

Solution

  1. Step 1: Understand combined options usage

    Both -f (follow) and --tail 10 (last 10 lines) can be combined in any order before the container name.
  2. Step 2: Check command syntax flexibility

    Docker accepts options in any order before the container name, so all listed commands are valid.
  3. Final Answer:

    All of the above -> Option A
  4. Quick Check:

    Options order flexible before container name [OK]
Hint: Options order flexible before container name [OK]
Common Mistakes:
  • Thinking options must be in fixed order
  • Placing options after container name
  • Using invalid flags or syntax
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard