Created
February 21, 2024 13:32
-
-
Save mattbell87/8d334115b32f25f755f783a78aa5ebd0 to your computer and use it in GitHub Desktop.
Get unhealthy container logs in a docker-compose project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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