Docker Log使用


前言

查看docker日志通常会使用到docker log指令,可以通过指令docker help logs来查看docker log提供的功能:
在这里插入图片描述

Options(可选参数):
–details 显示更多详细的信息
-f, --follow 跟踪实时日志
–since string 显示自某个(时间)timestamp之后的日志,或相对时间,如42m(即42分钟)
–tail string 显示日志末尾后N行, 默认是全部显示
-t, --timestamps 在每行日志前加上timestamp(时间戳)
–until string 显示日志某个时间戳之前的日志,或相对时间,如42m(即42分钟)


一、Docker logs 常用命令

docker log 提供了根据时间或者时间段查询日志,以及根据某个关键字查询日志的功能,以下将举例常用日志查看命令:

1. 查看docker容器:

docker ps : 列出容器
OPTIONS说明:
-a :显示所有的容器,包括未运行的。
-f :根据条件过滤显示的内容。
–format :指定返回值的模板文件。
-l :显示最近创建的容器。
-n :列出最近创建的n个容器。
–no-trunc :不截断输出。
-q :静默模式,只显示容器编号。
-s :显示总的文件大小。

2. 查看容器日志(全部):

docker logs -f 容器ID


3. 查看容器日志,只显示最后100行:

docker logs --tail 100 容器ID

4. 查看容器最近三十分钟的日志:

docker logs --since 30m 容器ID

5. 查看容器某个时间之后的日志:

这里演示的是查询2023年3月3日上午10点13分58秒后的日志
docker logs --since 2023-03-03T10:13:58.655 容器ID

6. 查看容器某个时间段的日志:

docker logs --since 2023-03-03T10:13:58.655 --until 2023-03-03T10:13:58.880 容器ID

7. 查看容器日志并显示时间戳:

docker logs -t 容器ID

8. 查看容器日志某个时间最近的日志:

这里演示的是十天内最新的十行日志信息
docker logs --tail 10 --since 240h 容器

9.将容器日志写入到文件:

这里演示的是将指定容器最后100日志写入error文件中
docker logs --tail 100 容器ID>>error.log

9.根据某个关键字查询日志:

这里演示的是根据error关键字查询日志
docker logs 容器ID | grep error

10.查询容器某个时间段的日志,并且根据关键字进行查询:

这里演示查看容器在2023年3月3日上午10点13分58秒665到880的日志,并根据关键字’Tomcat started on port’进行筛选
docker logs --since 2023-03-03T10:13:58.655 --until 2023-03-03T10:13:58.880 容器ID | grep ‘Tomcat started on port’

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The Docker overlay network driver is designed to provide a scalable and flexible networking solution for Docker containers running on multiple hosts. The overlay network driver allows Docker containers to communicate with each other seamlessly, regardless of the host they are running on. When using the overlay network driver, Docker logs are also handled differently than with other drivers. Docker logs from containers running on an overlay network are not automatically sent to the host's syslog daemon, as they are with the default bridge network driver. Instead, Docker logs are sent directly to the Docker daemon on the host where the container is running. To view Docker logs for containers running on an overlay network, you can use the `docker logs` command followed by the container ID or name. For example, to view the logs for a container named `my-container` running on an overlay network named `my-overlay-network`, you would use the following command: ``` docker logs my-container ``` If you want to view the logs for a container running on a specific host in an overlay network, you can use the `docker logs` command with the `--tail` and `--follow` options, followed by the container ID or name and the hostname. For example, to view the logs for a container named `my-container` running on a host named `my-host` in an overlay network named `my-overlay-network`, you would use the following command: ``` docker logs --tail 100 --follow my-container@my-host ``` This command will display the last 100 lines of logs for the container and continue to follow new logs as they are generated.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值