Elastic Beanstalk and Dockerfile ARG instruction

核能气质少年 提交于 2020-01-12 07:34:08

问题


I need to pass some arguments to my docker build command. I understand that this can be done using the ARG instruction within the Dockerfile. Now assuming I have the following in my Dockerfile.

ARG myvar

and use the command docker build --build-arg mvar=myOwnVar ..., this would work.

However, I am using AWS Elastic Beanstalk with Docker to build an image and deploy it in a container. So the questions are,

  1. Is this possible at all?
  2. If, yes how can I ensure that AWS EB passes values to these arguments?

Thanks Sushil


回答1:


yesterday I start using AWS EB, I was happy, today I need pass some ARG to my build, found this on the docs

Very sad

source: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-specific.html

Workaround

A possible solution is what I'm doing currently, before run the docker build add some files to the EB and the use it from the Dockerfile

example, lets assume I need a var name TOKEN on my docker something like

RUN curl http://somemething.com?token=$TOKEN

So whay I did was

add a new script file

ADD ./curl-thing.sh /curl-thing.sh

and the content of

if [ -f "./.env"]; then
  source ./.env
fi

now add a file name .ebextensions/my-env.config, the name no matters just important that exists on the forlder .ebextensions and have the extension .config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/02_mix_environment.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
      TOKEN=$(/opt/elasticbeanstalk/bin/get-config environment -k TOKEN)
      echo "export TOKEN=${TOKEN}" >> ${EB_APP_DEPLOY_DIR}/.env


来源:https://stackoverflow.com/questions/39698061/elastic-beanstalk-and-dockerfile-arg-instruction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!