Docker logs 命令
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