docker logs
Read a container's output: why it crashed, who visited it, the last lines or live as it happens.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
docker logs site -
docker logs --tail 1 site -
docker logs -t site -
docker logs site | grep GET -
docker logs -f web
How it works
docker logs NAME shows everything the container printed: startup messages, requests, and the error when it crashes.
It works on stopped containers too, which makes it the first stop when something won't start.
Syntax
docker logs [OPTIONS] CONTAINER
Options
| Option | What it does |
|---|---|
--tail N | only the last N lines |
-t | add a timestamp to each line |
-f | keep following new lines (Ctrl+C to stop) |
Good to know
- A container that exits at once?
docker ps -a, thendocker logs NAME: the reason is usually in the last lines. - Logs belong to the container:
docker rmdeletes them too.