diff --git a/docker-tail b/docker-tail index 515f8ac..45da8d2 100755 --- a/docker-tail +++ b/docker-tail @@ -57,9 +57,17 @@ for i in "${containers[@]}"; do # created a fixed length prefix containing the container name for each line of log output line_prefix=$(printf "|%-13s | " "$i") - # fork and spawn `docker logs -f`, feeding output through sed to add our prefix and colors - (docker logs --tail=10 --timestamps -f "$i" 2>&1 \ - | sed "s/^/$color$line_prefix/; s/$/$RESET_COLOR/") & + # fork and spawn `docker logs -f` with automatic reconnection, feeding output through sed to add our prefix and colors + ( + while true; do + if docker ps --format '{{.Names}}' | grep -q "^${i}$"; then + docker logs --tail=10 --timestamps -f "$i" 2>&1 \ + | sed "s/^/$color$line_prefix/; s/$/$RESET_COLOR/" + fi + # wait a bit before attempting to reconnect + sleep 2 + done + ) & cnt=$((cnt + 1)) done