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
1 Answer
Reset to default 0This 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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742420280a4440546.html
评论列表(0条)