Skip to content

Instantly share code, notes, and snippets.

@mattbell87
Created February 21, 2024 13:32
Show Gist options
  • Save mattbell87/8d334115b32f25f755f783a78aa5ebd0 to your computer and use it in GitHub Desktop.
Save mattbell87/8d334115b32f25f755f783a78aa5ebd0 to your computer and use it in GitHub Desktop.
Get unhealthy container logs in a docker-compose project
#!/bin/sh
services=$(docker compose config --services)
for service in $services; do
echo "Service: $service"
container=$(docker-compose ps -q $service)
if docker inspect $container --format='{{.State.Health.Status}}' >/dev/null 2>&1; then
health=$(docker inspect --format='{{json .State.Health.Status}}' $container)
if [ "$health" != "\"healthy\"" ]; then
echo "CONTAINER IS NOT HEALTHY"
echo "==== STATUS ===="
docker inspect --format='{{json .State.Health}}' $container
echo "==== LOGS ===="
docker logs $container
echo "==== END ===="
else
echo "Container is healthy"
fi
else
echo "Container does not have a health check"
fi
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment