Interview Q&A / Docker & Kubernetes

BeginnerQuick answer1 min readUpdated 3 Oct 2026

How do you view and follow the logs of a running container?

SHORT ANSWER

Use docker logs <container>. Add -f to follow new lines, --tail N to show only the last N lines, and --since to limit by time. It shows whatever the main process wrote to stdout and stderr.

Explain it simply

A container's logs are like the CCTV recording of a shop: you can replay all of it, jump to the last few minutes, or watch live.

Docker captures everything the main process writes to stdout and stderr and stores it using a logging driver (JSON files by default). That is why containerised apps should log to the console, not to a file inside the container. docker logs web prints everything so far. -f keeps the stream open like tail -f. --tail 50 limits output to the last 50 lines, --since 10m to the last ten minutes, and -t adds timestamps.

If docker logs is empty although the app is running, the app is probably writing to a file instead of the console. In Kubernetes the matching command is kubectl logs.

Example

bash
docker logs web
docker logs -f --tail 50 web         # live, starting from last 50 lines
docker logs --since 10m -t web       # last 10 minutes with timestamps
kubectl logs -f my-pod               # Kubernetes equivalent

What to say in the interview

"docker logs shows the container's stdout and stderr. I use -f to follow, --tail to limit lines and --since for a time window. If it is empty, the app likely logs to a file rather than the console."

Common mistakes

  • Logging to a file inside the container, which is lost on removal and invisible to docker logs.

#docker#commands#logging

Related questions

Practise more Docker & Kubernetes questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Docker & Kubernetes quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.