Currently using Elastic Beanstalk to run Docker containers, I need to pass important information as environment variables to my containers.
My current Dockerrun.aws.json looks like this:
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "b2boost/rabbitelasticdockstash",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "80"
}
],
"environment": [
{
"name": "RABBITMQ_HOST",
"value": "RABBITMQ_HOST"
},
{
"name": "RABBITMQ_PASSWORD",
"value": "RABBITMQ_PASSWORD"
},
{
"name": "RABBITMQ_USER",
"value": "RABBITMQ_USER"
},
{
"name": "RABBITMQ_VHOST",
"value": "RABBITMQ_VHOST"
},
{
"name": "ELASTICSEARCH_HOST",
"value": "ELASTICSEARCH_HOST"
},
{
"name": "ELASTICSEARCH_PASSWORD",
"value": "ELASTICSEARCH_PASSWORD"
},
{
"name": "ELASTICSEARCH_PORT",
"value": "ELASTICSEARCH_PORT"
},
{
"name": "ELASTICSEARCH_PROTOCOL",
"value": "ELASTICSEARCH_PROTOCOL"
},
{
"name": "ELASTICSEARCH_USER",
"value": "ELASTICSEARCH_USER"
}
],
"Volumes": [
],
"Logging": "/var/log/eb-activity.log"
}
This doesn't work however. When SSHing to my beanstalk instance then getting the content of the environment variables, I can see that they weren't initialized:
[ec2-user@myip ~]$ sudo docker exec goofy_curie env
PATH=/opt/logstash/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:bin
HOSTNAME=HOSTNAME
LANG=C.UTF-8
JAVA_VERSION=7u79
JAVA_DEBIAN_VERSION=7u79-2.5.5-1~deb8u1
LOGSTASH_MAJOR=1.5
LOGSTASH_VERSION=1:1.5.1-1
HOME=/root
How can I set the environment variables in my containers? The Dockerrun.aws.json doesn't seem to work for me.
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). For instance, let's execute the following command: $ docker run --env VARIABLE1=foobar alpine:3 env
You can pass environment variables to your containers with the -e flag. Or, if you don't want to have the value on the command-line where it will be displayed by ps, etc., -e can pull in the value from the current environment if you just give it without the =: sudo PASSWORD='foo' docker run [...] -e PASSWORD [...]
docker run --rm -it --env-file < (bash -c 'env | grep <your env data>') Is a way to grep the data stored within a .env and pass them to Docker, without anything being stored unsecurely (so you can't just look at docker history and grab keys.
The command used to launch Docker containers, docker run, accepts ENV variables as arguments. Simply run it with the -e flag, shorthand for --env, and pass in the key=value pair: sudo docker run -e POSTGRES_USER='postgres' -e POSTGRES_PASSWORD='password' ...
The "environment" field is not allowed in the Dockerrun.aws.json for single containers.
You can however specify the environment variables in a .config file with the following procedure (look at the documentation for more information):
option_settings: - option_name: RABBITMQ_HOST value: RABBITMQ_HOST - option_name: RABBITMQ_PASSWORD value: RABBITMQ_PASSWORD - option_name: RABBITMQ_USER value: RABBITMQ_USER - option_name: RABBITMQ_VHOST value: RABBITMQ_VHOST - option_name: ELASTICSEARCH_HOST value: ELASTICSEARCH_HOST - option_name: ELASTICSEARCH_PASSWORD value: ELASTICSEARCH_PASSWORD - option_name: ELASTICSEARCH_PORT value: ELASTICSEARCH_PORT - option_name: ELASTICSEARCH_PROTOCOL value: ELASTICSEARCH_PROTOCOL - option_name: ELASTICSEARCH_USER value: ELASTICSEARCH_USER
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With