mercredi 1 juillet 2015

Passing environment variables to Docker containers

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.




Aucun commentaire:

Enregistrer un commentaire