Skip to content

Commit 402c43a

Browse files
Add a script to check docker health
1 parent 2f21d23 commit 402c43a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

data/scripts/wait-for-docker.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Container name must be consistent with the name defined in the docker-compose.yaml
4+
CONTAINER_NAME="localstack-ts-api-gateway-lambda-dynamodb-crud"
5+
TIMEOUT=30 # Maximum wait time in seconds
6+
INTERVAL=2 # Interval between checks in seconds
7+
8+
# Loop to check the health status of the container
9+
for (( i=0; i<$TIMEOUT; i+=$INTERVAL )); do
10+
# Check if the container is healthy
11+
if [ "$(docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME 2>/dev/null)" == "healthy" ]; then
12+
echo "$CONTAINER_NAME is ready."
13+
exit 0
14+
fi
15+
echo "Waiting for $CONTAINER_NAME to be ready..."
16+
sleep $INTERVAL # Wait for the specified interval before checking again
17+
done
18+
19+
echo "$CONTAINER_NAME is not ready after $TIMEOUT seconds."
20+
exit 1 # Exit with a failure status

0 commit comments

Comments
 (0)