docker logs : 获取容器的日志
语法
docker logs [OPTIONS] CONTAINER
OPTIONS说明:
-
-f : 跟踪日志输出
-
--since :显示某个开始时间的所有日志
-
-t : 显示时间戳
-
--tail :仅列出最新N条容器日志
实例
跟踪查看容器myniginx的日志输出。
[root@node1 ~]# docker logs -f myniginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/09/15 01:46:49 [notice] 1#1: using the "epoll" event method
2021/09/15 01:46:49 [notice] 1#1: nginx/1.21.3
2021/09/15 01:46:49 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
.......
查看容器myniginx从2021年9月15日后的最新10条日志。
[root@node1 ~]# docker logs --since 2021-09-15 --tail=10 myniginx
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/09/15 02:59:34 [notice] 1#1: using the "epoll" event method
2021/09/15 02:59:34 [notice] 1#1: nginx/1.21.3
2021/09/15 02:59:34 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
2021/09/15 02:59:34 [notice] 1#1: OS: Linux 3.10.0-693.el7.x86_64
2021/09/15 02:59:34 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 65536:65536
2021/09/15 02:59:34 [notice] 1#1: start worker processes
2021/09/15 02:59:34 [notice] 1#1: start worker process 22
2021/09/15 02:59:34 [notice] 1#1: start worker process 23