DockerEntrypoint
- Example entry point file
- It creates a env.js file form environment variables - for use with SPA react/angular for runtime config
Add to Dockerfile as
COPY Dockerentrypoint.sh /Dockerentrypoint.sh ENTRYPOINT [ "/Dockerentrypoint.sh" ]
- at the last line it executes Docker CMD passed to docker
# Container startups script. # Allow for runtime configuration through env vars. # https://12factor.net/build-release-run set -e echo "# Start container with $0 PWD=${PWD}" echo "#" echo "# cat .version.txt" cat .version.txt echo "#" echo "# Add env vars REACT_APP_* to ''env.js'' at webserver root" echo "window.ENV = `jo -p \`env | grep REACT_APP_ | sed -e 's/[[:blank:]]/{_!!_}/g'\` end=1`" | sed -e 's/{_!!_}/ /g' | tee env.js echo "#" echo "# Starting docker cmd \$@=$@ ..." exec "$@"
AWS ECS docker entrypoint.sh script to add metadata on startup to .version.txt
# Container startups script. # Allow for runtime configuration through env vars. # https://12factor.net/build-release-run set -e echo "# Start container with $0 PWD=${PWD}" echo "#" # Get aws ecs container metadata, add to .version.txt if available. if [[ -z "${ECS_CONTAINER_METADATA_URI_V4}" ]]; then echo "# Not running in ECS, probably local." | tee -a .version.txt else echo "# aws ecs extracting metadata." | tee -a .version.txt echo "# curl -s ${ECS_CONTAINER_METADATA_URI_V4}" >> .version.txt curl -s "${ECS_CONTAINER_METADATA_URI_V4}" >> .version.txt || true echo "# aws ecs - The END." >> .version.txt fi echo "# cat .version.txt" cat .version.txt echo "#" echo "# Add env vars REACT_APP_* to ''env.js'' at webserver root" echo "export default () => (`jo -p \`env | grep REACT_APP_ | sed -e 's/[[:blank:]]/{_!!_}/g'\` end=1`)" | sed -e 's/{_!!_}/ /g' | tee env.js echo "#" echo "# Starting docker cmd \$@=$@ ..." exec "$@"
docker run override entrypoint
put --entrypoint just after run
docker run --entrypoint <entrypoint.sh> <image:tag> <arg1> <arg2> <arg3>