Skip to content

Instantly share code, notes, and snippets.

@alexpetrean80
Last active August 9, 2023 12:36
Show Gist options
  • Save alexpetrean80/55e36b8f6c7169c2f8c03342c410916d to your computer and use it in GitHub Desktop.
Save alexpetrean80/55e36b8f6c7169c2f8c03342c410916d to your computer and use it in GitHub Desktop.
A script that waits for a file to exist in a docker container with a timeout
#!/usr/bin/bash
FILE_PATH=$1
CONTAINER=$2
TIMEOUT=$3
start_time=$(date +%s)
while true; do
elapsed_time=$(($(date +%s) - start_time))
if [ $elapsed_time -gt $TIMEOUT ]; then
echo "Timeout reached"
exit 1
fi
docker compose exec "$CONTAINER" [ -f "$FILE_PATH" ] && break
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment