Skip to content

Instantly share code, notes, and snippets.

@fullkomnun
Created June 3, 2019 14:42
Show Gist options
  • Save fullkomnun/452c2e4d9c608b78136989edb84a8ae5 to your computer and use it in GitHub Desktop.
Save fullkomnun/452c2e4d9c608b78136989edb84a8ae5 to your computer and use it in GitHub Desktop.
A bash script that writes all logs from running docker containers to files called <container_name>.log and compresses these into an archive
#!/bin/bash
set -xe
for name in $(docker ps --format "{{.Names}}"); do
eval "docker logs \"$name\" 2> ${name}.log";
done
eval "env GZIP=-9 tar cvzf logs.tar.gz *.log"
@fullkomnun
Copy link
Author

On a Mac the compressing can be done using:
'tar -czf logs.tar.gz --options gzip:compression-level=9 *.log'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment