`docker stack`特定的日志位置 [英] `docker stack` specific log locations

查看:495
本文介绍了`docker stack`特定的日志位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 docker-compose.yml 文件在已部署的 docker 堆栈上指定日志文件?

Is there a way to specify logging file on a deployed docker stack with docker-compose.yml file?

我一直在遭受docker服务的间歇性崩溃以及在docker swarm上运行的堆栈的间歇性崩溃,并且没有留下任何日志跟踪,并且我需要一些可以查看的旋转日志在发生这些情况时

I've been suffering from intermittent crashes on docker services and stacks running on a docker swarm that leave no log trace behind, and I need some rotating logs that I can look at when these happen

我的码头工人信息输出:

$ docker info
Containers: 114
 Running: 4
 Paused: 0
 Stopped: 110
Images: 95
Server Version: 17.09.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog


推荐答案


  1. 是的@hichamx是正确的,您可以更改fi用于服务的默认JSON日志驱动程序的文件大小设置,但这可能不是您的问题。

  1. Yes @hichamx above is correct that you can change the file size settings of the default JSON log driver for services, but that likely isn't your issue.

删除容器时,日志也会被删除。使用Swarm Service时,这些任务仅挂在任务历史记录保留限制内,如 docker info 所示。默认值为5,这意味着4个旧任务会徘徊。如果您的服务任务在启动后很快崩溃,您就会发现...日志的时间不会太长。使用 docker swarm update --task-history-limit 在磁盘空间允许的情况下设置更大的数字。

Logs are deleted when containers are deleted. With a Swarm Service, those "tasks" only hang around the Task History Retention Limit as seen in docker info. This defaults to 5, which means 4 old tasks will hang around. If your service tasks are crashing quickly after startup, you get the idea... logs aren't around very long. Use docker swarm update --task-history-limit to set a bigger number, disk-space permitting.

docker服务日志仅显示您的应用向容器内stdout / stderr报告的内容。它们不会向您显示Swarm协调器正在采取的行动。为此使用 docker events 。它没有太多历史记录,因此您需要将其保留在外壳中或以其他方式捕获历史记录。 事件会告诉您诸如容器创建/删除/故障之类的事情。

docker service logs only shows what your apps report to stdout/stderr inside the containers. They won't show you actions the Swarm orchestrator are taking. Use docker events for that. It doesn't store much historical, so you'll need to keep that running in your shell or capture it some other way for historical. events tells you things like container creation/deletion/failure.

理想的情况是它是否属于应用程序在内部进行操作时,它将报告退出时发生的错误,docker会将其存储在容器中,检查 .State.Error 下的元数据。单线很酷,但有时并不像我们需要的那样灵活。这是一个示例,该示例首先在中列出所有任务,然后获取每个任务的容器ID,然后检查每个容器并显示错误(如果有)。不幸的是,它仅适用于您所连接的本地服务器上的容器,但是希望您能对每个 $()中的嵌套命令有所了解。

Ideally if it's something the app is doing internally, it'll report an error on exit, which docker will store in the container inspect metadata under .State.Error. One-liners are cool but sometimes not as flexible as we need them to be. Here's an example of one that first lists all tasks in a , then gets their container ID for each task, then inspects each container and shows the Error, if any. Unfortunately it only works against containers on the local server you're connected to, but hopefully, you get the idea of the nested commands inside each $() .

docker inspect -f {{.State.Error}} $(docker inspect -f {{.Status.ContainerStatus.ContainerID}} $(docker服务ps< servicename> -q))

这篇关于`docker stack`特定的日志位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆