Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
Step by step
- Find the container — also stopped ones:
docker ps -a --filter name=api
CONTAINER ID IMAGE STATUS NAMES
8d2e4f1a9b3c registry.example.com/shop/api:1.4.2 Exited (137) 3 minutes ago api- Read the exit code — it often tells you the reason before the log does:
| Exit code | Usual meaning |
|---|---|
0 | The process ended normally (a job finished, or the command was not a long-running server). |
1 | App error — read the log. |
137 | Killed with SIGKILL — very often out of memory (--memory limit) or docker kill. |
139 | Segmentation fault (crash in native code). |
143 | Stopped with SIGTERM (docker stop) — normal. |
docker inspect api --format '{{.State.ExitCode}} OOMKilled={{.State.OOMKilled}} {{.State.FinishedAt}}'
137 OOMKilled=true 2026-11-17T09:41:12Z- Filter by time (incidents have a time):
docker logs --since 2026-11-17T09:30:00 --until 2026-11-17T09:45:00 api
docker logs --since 1h api 2>&1 | grep -ciE 'error|exception'2>&1 is needed for grep, because many apps write errors to stderr.
- Logs of a restarting container (crash loop): look at the previous run's last lines and the restart count:
docker inspect api --format '{{.RestartCount}}'
docker logs --tail 30 api
docker events --filter container=api --since 30m- Where are the log files, and how big? (with the default
json-filedriver):
docker inspect api --format '{{.LogPath}}'
du -h /var/lib/docker/containers/*/*-json.log | sort -h | tail -5Set rotation for all containers in /etc/docker/daemon.json ("log-opts": {"max-size": "10m", "max-file": "3"}); it applies to new containers. For one container: docker run --log-opt max-size=10m --log-opt max-file=3 ….
- The app writes to a file inside the container? Then
docker logsis empty. Better: make the app log to stdout. Until then:
docker exec api tail -n 50 /app/logs/app.logCheck that it worked
You found the reason (log line or exit code). After the fix (more memory, fixed config), the container stays Up and docker inspect … RestartCount does not grow any more.
Common problems
| Problem | Cause | Fix |
|---|---|---|
docker logs shows nothing | The app logs to a file, not to stdout/stderr. | Log to stdout; or docker exec … tail the file. |
grep finds nothing, but errors are on screen | Errors go to stderr. | Add 2>&1 before the pipe. |
| Exit code 137, no error in the log | OOM kill — the process had no time to log. | docker inspect (OOMKilled); raise --memory or fix the leak. |
| Logs are gone | The container was removed (docker rm, --rm). | Send logs to a central system (Loki, ELK); do not rely on local logs. |
Disk full by *-json.log | No log rotation. | max-size/max-file in daemon.json, recreate the containers. |
configured logging driver does not support reading | The container uses syslog/gelf etc. | Read them in that system; with journald: journalctl CONTAINER_NAME=api. |
Go further
- Command pages: docker, journalctl, grep.
- Next how-tos: Run a container and publish a port, Free disk space used by Docker, Read the logs of a service.
- Learn it: Docker — Logs and exec. In Kubernetes: kubectl debug flow.
- Central logs: Loki, Fluent Bit, Elasticsearch.
1A container stopped with exit code 137 and an empty log. What do you check first?
docker inspect for OOMKilled=true — the memory limit killed it.
2Why does docker logs api | grep error miss lines?
Errors are on stderr; use docker logs api 2>&1 | grep error.