Skip to content

Instantly share code, notes, and snippets.

@othyn
Last active February 5, 2020 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save othyn/321582324a0a2374195721637de95bf1 to your computer and use it in GitHub Desktop.
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.
#!/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