Last active
February 5, 2020 16:40
-
-
Save othyn/321582324a0a2374195721637de95bf1 to your computer and use it in GitHub Desktop.
Docker entrypoint.sh to launch either sh/bash or node depending on the script shebang executable type. This came from a personal circumstance where to save resources, one node image could be used to run shell scripts and node scripts that both performed actions against the same resource. This condensed 4 containers into 1, giving the same result.
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/sh | |
set -e | |
FIRST_LINE=$(head -n 1 "${1}") | |
# As the scripts can be either JS or shell, determine how to exec! | |
if [ "${FIRST_LINE}" = "#!/bin/sh" ] || [ "${FIRST_LINE}" = "#!/bin/bash" ]; then | |
eval "./$@" | |
else | |
# https://github.com/nodejs/docker-node/blob/master/docker-entrypoint.sh | |
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ]; then | |
set -- node "$@" | |
fi | |
exec "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment