2015-07-01 116 views
7

當前使用Elastic Beanstalk運行Docker容器,我需要將重要信息作爲環境變量傳遞到我的容器。將環境變量傳遞給Docker容器

我現在Dockerrun.aws.json看起來是這樣的:

{ 
    "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" 
} 

然而,這並不工作。當ssh方式連接到我的豆莖實例,然後獲取環境變量的內容,我可以看到他們未初始化:

[[email protected] ~]$ 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 

如何設置環境變量在我的容器? Dockerrun.aws.json似乎不適合我。

+1

你試試這個選項:http://stackoverflow.com/questions/28298101/elastic-beanstalk-environment-variables爲碼頭主人? –

+1

如果您不希望將信息保留在VCS上,則可以使用Web控制檯。它適用於我的dockerized環境。 http://stackoverflow.com/a/17878600/1102395 – Samar

回答

9

對於單個容器,Dockerrun.aws.json中不允許使用「環境」字段。

  1. 創建一個文件夾.ebextensions
  2. 創建一個config文件:

    但是,您可以通過以下步驟(看documentation獲取更多信息)指定的config文件中的環境變量該文件夾

  3. 填充配置文件:
 
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 
  • 郵編.ebextensions與Dockerrun.aws.json文件一起,並上傳到魔豆
  • +0

    如果你不捆綁,而是在碼頭集線器上指定一個圖像? '.ebextensions'去哪了? – Luke

    +0

    @Luke你還需要在Dockerrun.aws.json文件中指定Docker Hub鏡像嗎?因此,使用Dockerrun.aws.json和.ebextensions創建一個git存儲庫,然後使用EB CLI輕鬆部署配置。 –

    相關問題