Reputation: 3383
I currently use docker for my backend, and when I first start them up with
docker-compose up
I get log outputs of all 4 dockers at once, so I can see how they are interacting with each other when a request comes in. Looking like this, one request going from nginx to couchdb
The issue is now that I am running on GCE with load balancing, when a new VM spins up, it auto starts the dockers and runs normally, I would like to be able to access a load balanced VM and view the live logs, but I can not get docker to allow me this style, when I use logs, it gives me normal all white font with no label of where it came from.
Using
docker events
does nothing, it won't return any info.
tldr; what is the best way to obtain a view, same as the log output you get when running "docker-compose up"
Upvotes: 69
Views: 85615
Reputation: 4133
Make sure that the last process stays in foreground.
(trap 'kill 0' SIGINT; docker logs -f container1 & docker logs -f container2 & docker logs -f container3)
Upvotes: 1
Reputation: 9955
You can see the logs for all running containers with
docker ps -q | xargs -L 1 docker logs
This may work with the --follow
too if xargs is ran with -P <count>
, where the count is higher than the number of running containers (thx @kisna for the example):
docker ps -q | xargs -L 1 -P `docker ps | wc -l` docker logs --since 30s -f
Upvotes: 85
Reputation: 3106
Here's a quick and dirty multitail/xtail for docker containers.
watch 'docker ps --format "{{.Names}}" | sort | xargs --verbose --max-args=1 -- docker logs --tail=8 --timestamps'
How this works:
watch
to run every few seconds
docker ps --format "{{.Names}}"
to get the names of all running containerssort
to sort themxargs
to give these names to docker logs
:
docker logs
to print the actual logsAdjust parameter "--tail=8" as needed so that everything still fits on one screen.
The "xargs" methods listed above (in another user's answer) will stop working as containers are stopped and restarted. This "watch" method here does not have that problem. (But it's not great either.)
Upvotes: 9
Reputation: 614
If you are using Docker Swarm, you can find your services by
docker service ls
Grap the id, and then run
docker service logs $ID -f
if the service is defined with tty: true, then you must run with the --raw flag. Notice, this wont tell you which container is giving the outputted log entry.
Upvotes: 4
Reputation: 1200
I use a variation of this to live tail (--follow) all logs and indicate which log is tailing at the time. This bash includes both stdout and stderr. Note you may need to purge the /tmp dir of *.{log,err} afterwards.
for c in $(docker ps -a --format="{{.Names}}")
do
docker logs -f $c > /tmp/$c.log 2> /tmp/$c.err &
done
tail -f /tmp/*.{log,err}
Hope this helps. Logging has become so problematic these days, and other get-off-my-lawn old man rants...
Upvotes: 24
Reputation: 3383
If using docker-compose, you use
docker-compose logs --tail=0 --follow
instead of
docker logs --tail=0 --follow
This will get the output I was originally looking for.
Upvotes: 102