View Docker Container Logs

View Docker Container Logs

Logs are an important thing that helps debug applications, troubleshoot issues, fix bugs, track patterns, etc. Docker provides a built-in logging solution. This tutorial demonstrates how to view Docker container logs.

View logs

To view a running container logs by its ID or name, use docker logs command or docker container command with logs argument. For example, to view logs of a container named nginx, you can use:

docker logs nginx
docker container logs nginx

An example of part of the output:

...
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/11/03 02:24:03 [notice] 1#1: using the "epoll" event method
2022/11/03 02:24:03 [notice] 1#1: nginx/1.23.2
2022/11/03 02:24:03 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2022/11/03 02:24:03 [notice] 1#1: OS: Linux 5.15.0-52-generic
2022/11/03 02:24:03 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/11/03 02:24:03 [notice] 1#1: start worker processes
2022/11/03 02:24:03 [notice] 1#1: start worker process 29
...

View only latest log lines

By default, all container logs are displayed. The -n or --tail option can be used to view a specified number of lines from the end of the logs. For example, to view latest 10 lines, you can use:

docker logs -n 10 nginx
docker container logs -n 10 nginx

View logs since

We can view logs from a specific point of time until now by using --since option. It accepts date and time (e.g. 2022-11-03T02:56:30Z, 2022-11-03) or relative value (e.g. 10m for 10 minutes). For example, to view logs within the last 1 hour, you can use:

docker logs --since 1h nginx
docker container logs --since 1h nginx

Leave a Comment

Cancel reply

Your email address will not be published.