How do I tail the logs of ALL my docker containers?

If you are using docker-compose, this will show all logs from the diferent containers

docker-compose logs -f

If you have access and root to the docker server:

tail -f  /var/lib/docker/containers/*/*.log

The docker logs command can't stream multiple logs files.

Logging Drivers

You could use one of the logging drivers other than the default json to ship the logs to a common point. The systemd journald or syslog drivers would readily work on most systems. Any of the other centralised log systems would work too.

Note that configuring syslog on the Docker daemon means that docker logs command can no longer query the logs, they will only be stored where your syslog puts them.

A simple daemon.json for syslog:

{
  "log-driver": "syslog",
  "log-opts": {
    "syslog-address": "tcp://10.8.8.8:514",
    "syslog-format": "rfc5424"
  }
}

Compose

docker-compose is capable of streaming the logs for all containers it controls under a project.

API

You could write tool that attaches to each container via the API and streams the logs via a websocket. Two of the Java libararies are docker-client and docker-java.

Hack

Or run multiple docker logs and munge the output, in node.js:

const { spawn } = require('child_process')

function run(id){
  let dkr = spawn('docker', [ 'logs', '--tail', '1', '-t', '--follow', id ])
  dkr.stdout.on('data', data => console.log('%s: stdout', id, data.toString().replace(/\r?\n$/,'')))
  dkr.stderr.on('data', data => console.error('%s: stderr', id, data.toString().replace(/\r?\n$/,'')))
  dkr.on('close', exit_code => {
    if ( exit_code !== 0 ) throw new Error(`Docker logs ${id} exited with ${exit_code}`)
  })
}

let args = process.argv.splice(2)
args.forEach(arg => run(arg))

Which dumps data as docker logs writes it.

○→ node docker-logs.js 958cc8b41cd9 1dad69882b3d db4b844d9478
958cc8b41cd9: stdout 2018-03-01T06:37:45.152010823Z hello2
1dad69882b3d: stdout 2018-03-01T06:37:49.392475996Z hello
db4b844d9478: stderr 2018-03-01T06:37:47.336367247Z hello2
958cc8b41cd9: stdout 2018-03-01T06:37:55.155137606Z hello2
db4b844d9478: stderr 2018-03-01T06:37:57.339710598Z hello2
1dad69882b3d: stdout 2018-03-01T06:37:59.393960369Z hello