Created
August 25, 2017 14:39
-
-
Save l4sh/93ed87a921a0418746349c32e97bafb2 to your computer and use it in GitHub Desktop.
Check if a Redis container running on docker is OK by sending a PING to redis instance running in container
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 | |
# | |
# Check if a Redis container running on docker is OK | |
# by sending a PING to redis instance running in container | |
if [[ $# -eq 0 ]] ; then | |
echo 'Send PING to redis instance running in docker container' | |
echo 'It should return PONG+' | |
echo 'Usage:' | |
echo ' check_redis.sh container_name' | |
exit 0 | |
fi | |
CONTAINER_NAME=$1 | |
CONTAINER_ID=$(docker ps | \ | |
grep $CONTAINER_NAME | \ | |
cut -d\ -f1) | |
echo "Container ID: $CONTAINER_ID" | |
CONTAINER_IP=$(docker inspect $CONTAINER_ID | \ | |
awk '/"IPAddress": "[0-9]{1,3}/ { | |
gsub(/("|,)/, "", $2); print $2 | |
}') | |
echo "PING redis @ $CONTAINER_IP" | |
echo $((printf "PING\r\n";) | nc $CONTAINER_IP 6379) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment