Read container logs
Container logs are the text a containerized app writes to standard output and standard error, which Docker stores and lets you read.
- Updated Nov 27, 2026
- Markdown
Read, filter and follow container logs with docker logs and docker compose logs.
- A running container or Compose app
Your site returns errors and the dashboard says nothing useful. The answer is almost always a line the app printed a few seconds ago. Knowing how to read, narrow and follow logs turns a vague outage into a specific error message.
How it works#
Inside a container, the main process writes to two streams: standard output (stdout) and standard error (stderr). Docker’s logging driver captures both. With the default json-file driver, Docker writes each line to a JSON file on the host, under the Docker data directory, with a timestamp and the stream name. docker logs reads that file back for you.
Three consequences follow. First, only what goes to stdout or stderr is captured, so an app that writes to /var/log/app.log inside the container shows nothing. Second, the log belongs to the container: remove the container and its log is gone. Third, json-file has no size limit by default, so a chatty app can fill the disk over weeks.
Other drivers (such as syslog, journald or none) send logs elsewhere. Depending on the driver, docker logs may not work, and you read the logs where they were sent.
Step 1: Read the logs#
docker logs my-containerFind the container name with docker ps.
What you should see: the full log of that container from its start, which can be long. Use the next step to narrow it.
Step 2: Narrow and follow#
docker logs --tail 100 my-container
docker logs --since 10m my-container
docker logs -t my-container
docker logs -f my-container--tail 100shows the last 100 lines.--since 10mshows only the last ten minutes. It also accepts a timestamp.-tadds a timestamp to each line.-ffollows new lines live. Press Ctrl+C to stop.
You can combine them: docker logs -f --tail 50 -t my-container.
What you should see: only the requested lines. With -f the command stays running and prints each new line as it arrives.
Step 3: Use Compose#
docker compose logs
docker compose logs -f --tail 100 webNaming a service (web) limits output to it. Without a name you see every service, each line prefixed by the service name. Run it from the folder that holds compose.yaml.
What you should see: lines like web-1 | GET /health 200, with the prefix showing which container wrote them.
Step 4: Limit log size#
Rotation stops logs from growing forever. In compose.yaml:
services:
web:
image: myapp:latest
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"This keeps up to 3 files of 10 MB each per container. Recreate the container for it to apply: docker compose up -d.
What you should see: Compose prints that the service is recreated. The first-time Recreated or Started line confirms the new settings are in use.
Check it worked#
docker logs --tail 5 my-containerprints recent lines.docker inspect --format '{{.HostConfig.LogConfig}}' my-containershows the driver and your options, for example{json-file map[max-file:3 max-size:10m]}.
Edge cases and gotchas#
- Output can be mixed.
docker logsreplays stdout and stderr on the matching streams, sodocker logs my-container | grep errormisses stderr lines. Add2>&1:docker logs my-container 2>&1 | grep error. - Recreating a container deletes its logs.
docker compose up -dafter an image update replaces the container. Read the logs of a failing release before you redeploy, or ship them elsewhere. - A restart loop hides the real error. If a container restarts every few seconds,
docker logs --tail 50shows the latest start only. The first crash line may be just above it. - Apps that buffer output look silent. Some runtimes buffer stdout when not attached to a terminal, so lines appear late. Look for an unbuffered or line-buffered setting in your language runtime.
- Time zones differ. Docker timestamps are in UTC. Your app may log in local time. Mind this when you compare lines with a user report.
- Limits do not apply retroactively. A changed
max-sizeaffects only containers created afterwards. - Large logs are slow.
docker logson a huge file with no--tailcan take a long time and flood the terminal.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
Error response from daemon: No such container: web | Wrong name, or the container was removed | Run docker ps -a and use the exact name |
| Empty output from a running container | App writes to a file, not stdout or stderr | Log to stdout, or read the file with docker exec |
docker logs prints an error about the logging driver | Driver does not support reading logs back | Read logs from the driver’s destination, or switch to json-file |
| Old lines are gone | Rotation deleted them, or the container was recreated | Expected; raise max-file if you need more history |
Disk is full and /var/lib/docker is big | No max-size on json-file | Set limits, recreate containers, see Limit Docker log size |
docker compose logs shows nothing | Wrong folder or project name | cd to the project, or pass -p and -f for the right project |
Lines arrive late with -f | App output is buffered | Disable buffering in the app runtime |
docker compose logs is slow and huge | No --tail on a long-running service | Add --tail 200 |
| Timestamps look wrong by hours | -t shows UTC, the app logs local time | Compare in one time zone |
Real-world scenario#
A customer reports that saving a profile fails. You do not know which service handles it, so you start with the whole stack for the last few minutes:
docker compose logs --since 10m -t 2>&1 | grep -i errorOne line stands out: api-1 | error: connection to database refused. You follow only that service while you reproduce the problem:
docker compose logs -f --tail 20 apiThe log shows the connection attempts failing. docker compose ps then shows the database container restarting. You read its logs, find that it ran out of disk space, free the space, and the API reconnects by itself. Total time: a few minutes, and no guessing, because the logs named the failing dependency.
Quick reference#
| Goal | Command |
|---|---|
| Last 100 lines | docker logs --tail 100 NAME |
| Last 10 minutes | docker logs --since 10m NAME |
| Follow live with times | docker logs -f -t NAME |
| One Compose service | docker compose logs -f --tail 100 web |
| Include errors in grep | docker logs NAME 2>&1 | grep -i error |
| Show log settings | docker inspect --format '{{.HostConfig.LogConfig}}' NAME |
Related lessons#
Next#
Automate how changes reach your server: What is CI/CD?.
Try it: Read the logs of a container
Find the container, read recent lines, follow them and check the rotation settings.
Want a real machine? Free browser labs: Killercoda
Check what you learned
Frequently asked questions
Why are my logs empty?
Docker only captures what the app writes to stdout and stderr. If the app writes to a file inside the container, it will not show in docker logs.
Can logs fill my disk?
Yes. With the default json-file driver there is no size limit unless you set one, so configure max-size and max-file.
Why did my logs disappear after I recreated the container?
Logs belong to the container. When you remove and recreate it, for example with docker compose up after an image change, the old log goes with the old container.
Why does docker logs say nothing is available?
Some logging drivers send logs elsewhere and docker logs cannot read them back. Check the driver with docker inspect and read the logs from where they were sent.
Sources
Keep going: guides and tutorials
- Zero Downtime Deploy for Docker Apps, With Rollback How a Docker deploy waits for readiness before cutover, holds the previous release for rollback, rolls back on its own, and how to rehearse it.
- Roll Back a Failed Docker Deploy Without Downtime Ship a broken release on purpose, watch your users stay on the old version, then roll back with one command. Real commands, real output, self-hosted.
- Our Health Check Failed and the Deploy Went Live Anyway A postmortem from our own dogfood run: a failed readiness probe still received traffic. What broke, why two correct parts added up to a bug, and the fix.