Tail stdout from multiple Docker containers -


i have script starts 10 containers in background mode (fig -d option). want aggregate stdout or log in /var/log of them. how can this?

the containers started using different docker-compose files can not docker-compose target1 target2 target3

docker logs accepts 1 container parameter.

i considering creating volume /var/log on containers, mapping them directory outside of docker, making sure logs not have colliding name , using bash tail -f * . appreciate more elegant solution

this bash script want:

docker-logs

#!/bin/bash  while [ $# -ne 0 ]     (docker logs -f -t --tail=10 $1|sed -e "s/^/$1: /")&     shift done wait 

usage:

$ docker-logs containerid1 containerid2 ... containeridn 

the output of script has each line tracked logs prepended container id.

the script works in --follow mode , must interrupted ctrl-c.

note options of docker logs hardcoded in script. if need able control options of docker logs command line need parse command line arguments (for example getopts).


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -