Last active
November 6, 2018 21:41
-
-
Save andrewodri/6680e4fc18605a54514746ca80e367d1 to your computer and use it in GitHub Desktop.
Check Docker Container Health
This file contains hidden or 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/bash | |
function is_container_healthy { | |
INSTANCE_ID=$(docker ps --filter "name=$1" --format "{{.ID}}") | |
IS_HEALTHY=$(docker inspect -f '{{if eq "healthy" .State.Health.Status}}0{{else}}1{{end}}' "${INSTANCE_ID}") | |
return "${IS_HEALTHY}" | |
} |
This file contains hidden or 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/bash | |
# Get available instance IDs below: | |
# aws ec2 describe-instances | |
INSTANCE_ID="i-00000000000000000" | |
DOCKER_PS_ID=$(aws ssm send-command --instance-ids "${INSTANCE_ID}" --document-name "AWS-RunShellScript" --parameters "commands=sudo docker ps --format '{{.Names}}'" --query "Command.CommandId" --output text) | |
while true; do | |
sleep 1 | |
DOCKER_PS_STATUS=$(aws ssm list-command-invocations --instance-id "${INSTANCE_ID}" --command-id "${DOCKER_PS_ID}" --query "CommandInvocations[].Status" --output text) | |
echo "Command execution on \"${INSTANCE_ID}\" is \"${DOCKER_PS_STATUS}\"..." | |
[[ "${DOCKER_PS_STATUS}" == "InProgess" ]] || break | |
done | |
DOCKER_PS_RESULT=$(aws ssm list-command-invocations --instance-id "${INSTANCE_ID}" --command-id "${DOCKER_PS_ID}" --details --query "CommandInvocations[].CommandPlugins[].Output" --output text) | |
echo "${DOCKER_PS_RESULT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment