Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Start a container on elastic beanstalk with the full configuration provided in the deployment script(s).
#!/usr/bin/env bash
set -e
. /opt/elasticbeanstalk/hooks/common.sh
# switch to current app directory
cd $EB_CONFIG_APP_CURRENT
# Dockerrun.aws.json can override settings in Dockerfile
echo "Reading settings from Dockerrun.aws.json"
if [ -f $EB_CONFIG_APP_CURRENT/Dockerrun.aws.json ]; then
EB_CONFIG_DOCKER_LOG_CONTAINER_DIR=`cat $EB_CONFIG_APP_CURRENT/Dockerrun.aws.json | jq -r .Logging`
# get volume mounting points from Dockerrun.aws.json
# this cannot be specified in Dockerfile since the host dir is host specific
EB_CONFIG_DOCKER_VOLUME_MOUNTS=()
while read VOLUME; do
EB_CONFIG_DOCKER_VOLUME_MOUNTS+=(-v "$VOLUME")
done < <(cat $EB_CONFIG_APP_CURRENT/Dockerrun.aws.json | jq -c '.Volumes[] | [.HostDirectory, .ContainerDirectory]' | sed -e 's/[]["]//g' -e 's/,/:/g')
fi
# build --env arguments for docker from env var settings
echo "Loading defined env variables"
EB_CONFIG_DOCKER_ENV_ARGS=()
while read ENV_VAR; do
EB_CONFIG_DOCKER_ENV_ARGS+=(--env "$ENV_VAR")
done < <(sudo $EB_SUPPORT_FILES/generate_env.py)
echo "Running command in docker container $@"
echo "${EB_CONFIG_DOCKER_ENV_ARGS[@]}"
sudo docker run -t -i \
"${EB_CONFIG_DOCKER_ENV_ARGS[@]}" \
"${EB_CONFIG_DOCKER_VOLUME_MOUNTS[@]}" \
$EB_CONFIG_DOCKER_PORT_MAPPING \
$EB_CONFIG_DOCKER_IMAGE_CURRENT "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment