Search code examples
dockeramazon-elastic-beanstalk

Docker on Elastic Beanstalk => Run terminal with environment configuration


Running EBS with Single Docker Container. I have used the environment variables configuration of EBS to set things like connection strings, etc.

I'd like to connect to a machine and run a terminal in a new container.

That's easy enough, I would just need to:

eb ssh

and then

sudo docker run -it my-image bash

However, I want that terminal environment to have the same configuration as the application (think of heroku run).

It looks like the environment is assembled for the actual application run in /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh, but I haven't had any luck adapting it to my purposes.

Is there an approved way to accomplish this?


Solution

  • This question is closely related to https://stackoverflow.com/questions/31572970/how-to-run-rails-migrations-and-seeding-in-amazon-elastic-beanstalk-single-conta/31932687#31932687_ and I am using @nmott 's answer for this:

    #! /usr/bin/env bash
    
    . /opt/elasticbeanstalk/hooks/common.sh
    
    EB_SUPPORT_FILES=$(/opt/elasticbeanstalk/bin/get-config container -k support_files_dir)
    
    EB_CONFIG_DOCKER_ENV_ARGS=()
    
    while read -r ENV_VAR; do
      EB_CONFIG_DOCKER_ENV_ARGS+=(--env "$ENV_VAR")
    done < <($EB_SUPPORT_FILES/generate_env)
    
    docker run --rm "${EB_CONFIG_DOCKER_ENV_ARGS[@]}" -it <image> bash