Skip to content

Instantly share code, notes, and snippets.

@gtoselli
Last active November 17, 2021 17:44
Show Gist options
  • Save gtoselli/b3598f6ca413442663f979ba45938bd0 to your computer and use it in GitHub Desktop.
Save gtoselli/b3598f6ca413442663f979ba45938bd0 to your computer and use it in GitHub Desktop.
Docker ENTRYPOINT for env check before container start
#!/bin/bash
echo "Environment variables check:"
declare -a unset=()
while IFS= read -r line
do
var_name="${line//=}"
if [[ -z "${!var_name+x}" ]]; then
echo "- $var_name is unset."
unset+=($var_name)
fi
done < ".env"
if (( ${#unset[@]} > 0)); then
echo "${#unset[@]} unset vars. Exit! 🛑"
exit 1
else
echo "All vars set. Continue! ✅"
fi
APP_NAME=
ENV_NAME=
APP_PORT=
#!/bin/sh
set -e
./check_env.sh
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment