问题
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,
- Is this possible at all?
- 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