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...:
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...:
Is there a way to make all (or just some) Docker containers log into the same log?
linux
docker
logging
docker-swarm
Share
Improve this question
edited Nov 20, 2024 at 6:08
Vinay Sajip
99.6k1515 gold badges183183 silver badges195195 bronze badges
asked Nov 19, 2024 at 15:09
DanijelDanijel8,6201919 gold badges8484 silver badges148148 bronze badges1
2you 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
CommentedNov 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