Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Elastic Beanstalk environment properties in Docker

So I've been looking around for an example of how I can specify environment variables for my Docker container from the AWS EB web interface. Typically in EB you can add environment properties which are available at runtime. I was using these for my previous deployment before I switched to Docker, but it appears as though Docker has some different rules with regards to how the environment properties are handled, is that correct? According to this article [1], ONLY the AWS credentials and PARAM1-PARAM5 will be present in the environment variables, but no custom properties will be present. That's what it sounds like to me, especially considering the containers that do support custom environment properties say it explicitly, like Python shown here [2]. Does anyone have any experience with this software combination? All I need to specify is a single environment variable that tells me whether the application is in "staging" or "production" mode, then all my environment specific configurations are set up by the application itself.

[1] http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options.html#command-options-docker

[2] http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options.html#command-options-python

like image 959
iLoch Avatar asked Aug 05 '14 23:08

iLoch


People also ask

How do I access Elastic Beanstalk environment variables?

Elastic Beanstalk lets you enter the environment variables for each environment using the management panel. On AWS, open Elastic Beanstalk. Go to your Application > Environment > Configuration > Software Configuration . Under Environment Properties you will find a list of properties you can configure.

How do you use Elastic Beanstalk with Docker?

Deploy to the Cloud Using the Elastic Beanstalk Console Choose “AWS Cloud9” and “Go To Your Dashboard.” Choose “Services” and “Elastic Beanstalk.” At the top right, choose “Create Application.” Paste flask-app for the “Application Name.” For “Platform,” choose “Docker.” Leave the Docker settings as is.

Can Docker container access environment variables?

docker pull alpine:3. When we launch our Docker container, we can pass environment variables as key-value pairs directly into the command line using the parameter –env (or its short form -e).

How can I see environment variables in container?

Fetch Using docker exec Command Here, we are executing the /usr/bin/env utility inside the Docker container. Using this utility, you can view all the environment variables set inside Docker containers.


2 Answers

Custom environment variables are supported with the AWS Elastic Beanstalk Docker container. Looks like a miss in the documentation. You can define custom environment variables for your environment and expect that they will be passed along to the docker container.

like image 150
Rohit Banga Avatar answered Oct 08 '22 19:10

Rohit Banga


I've needed to pass environment variable in moment docker run using Elastic Beanstalk, but, is not allowed put this information in Dockerrun.aws.json.

Below the steps to resolve this scenario:

  1. Create a folder .ebextensions
  2. Create a .config file in the folder
  3. Fill the .config file:

option_settings:
-option_name: VARIABLE_NAME value: VARIABLE_VALUE

  1. Zip the folder .ebextensions file along with the Dockerrun.aws.json plus Dockerfile and upload it to Beanstalk

To see the result, inside EC2 instance, execute the command "docker inspect CONTAINER_ID" and will see the environment variable.

like image 26
Renato Coutinho Avatar answered Oct 08 '22 20:10

Renato Coutinho