/ 设置 10 秒超时 // 每日统计清 0 runtime_set('todaycomments', 0); runtime_set('todayarticles', 0); runtime_set('todayusers', 0); if ($forumlist) { $fidarr = array(); foreach ($forumlist as $fid => $forum) { $fidarr[] = $forum['fid']; } forum_update($fidarr, array('todayposts' => 0, 'todaythreads' => 0)); } // 清理临时附件 attach_gc(); // 当天24点 $today = strtotime(date('Ymd')) + 86400; runtime_set('cron_2_last_date', $today, TRUE); // 往前推8个小时,尽量保证在前一天 升级过来和采集的数据会很卡 // table_day_cron($time - 8 * 3600); cache_delete('cron_lock_2'); } } } ?>linux - Can all Docker containers from Docker swarm log into the same log file? - Stack Overflow|Concepts Of Algorithm

linux - Can all Docker containers from Docker swarm log into the same log file? - Stack Overflow

admin2025-03-20  8

I've got several Docker containers running together as a Docker swarm. The software running in each of the containers is a Python code. Each of the components writes into their own log. When I debug the whole system, I constantly find myself greping through many logs in parallel trying to arrange the log entries in order...:

> docker container logs -f container1
> docker container logs -f container2
> docker container logs -f container3

Is there a way to make all (or just some) Docker containers log into the same log?

I've got several Docker containers running together as a Docker swarm. The software running in each of the containers is a Python code. Each of the components writes into their own log. When I debug the whole system, I constantly find myself greping through many logs in parallel trying to arrange the log entries in order...:

> docker container logs -f container1
> docker container logs -f container2
> docker container logs -f container3

Is there a way to make all (or just some) Docker containers log into the same log?

Share Improve this question edited Nov 20, 2024 at 6:08 Vinay Sajip 99.6k15 gold badges183 silver badges195 bronze badges asked Nov 19, 2024 at 15:09 DanijelDanijel 8,62019 gold badges84 silver badges148 bronze badges 1
  • 2 you should look into the different log drivers docker offers docs.docker/engine/logging/configure/… if you consolidate the logs you can look through them all in one place. – erik258 Commented Nov 19, 2024 at 15:12
Add a comment  | 

1 Answer 1

Reset to default 0

This is possible, You can redirect all Docker logs into a central file using a custom script that combines docker logs for each container and timestamps them.

#!/bin/bash
output_file="/path/to/centralized-log.log"
containers=$(docker ps --format "{{.Names}}")

for container in $containers; do
    docker logs -f "$container" | sed "s/^/[$container] /" >> "$output_file" &
done

wait

In Docker Swarm, you can use services like Fluentd, Graylog, or a shared space for all logs

version: '3.*'
services:
  app:
    image: my-app
    logging:
      driver: "fluentd"
      options:
        fluentd-address: "fluentd:****"

(Replace the * with numbers that you are using)

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1742420281a212900.html

最新回复(0)