docker logs
command is used to fetch the logs of a container.
$ docker logs [OPTIONS] CONTAINER
Note: This command only works for the containers that are started with the json-file or journald logging driver.
--details
→ Show extra details provided to logs--follow
, -f
→ Follow the log output--since
→ Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)--tail
, -n
→ Number of lines to show from the end of the logs--timestamps
, -t
→ Show timestamps--until
→ Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)$ docker run --name test -d busybox sh -c "while true; do $(echo date); sleep 1; done"
$ date
Tue 5 Jul 2022 15:56:25 UTC+5:45
Here, this command when executed successfully, dates are echoed continuously after every 1 second.
$ docker logs -f --until=2s test
Tue 5 Jul 2022 15:57:15 UTC+5:45
Tue 5 Jul 2022 15:57:16 UTC+5:45
Tue 5 Jul 2022 15:57:17 UTC+5:45