Elastic Beanstalk和Dockerfile ARG指令 [英] Elastic Beanstalk and Dockerfile ARG instruction
问题描述
我需要将一些参数传递给我的docker build
命令.我了解可以使用Dockerfile
中的ARG
指令来完成此操作.现在假设我在Dockerfile
中具有以下内容.
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
并使用命令docker build --build-arg mvar=myOwnVar ...
,这将起作用.
and use the command docker build --build-arg mvar=myOwnVar ...
, this would work.
但是,我将AWS Elastic Beanstalk
与Docker
结合使用来构建映像并将其部署在容器中.问题是,
However, I am using AWS Elastic Beanstalk
with Docker
to build an image and deploy it in a container. So the questions are,
- 这有可能吗?
- 如果可以,我如何确保AWS EB将值传递给这些参数?
谢谢 苏菲尔(Sushil)
Thanks Sushil
推荐答案
昨天我开始使用AWS EB,感到很高兴,今天我需要将一些ARG传递给我的构建,并在文档中找到了
yesterday I start using AWS EB, I was happy, today I need pass some ARG to my build, found this on the docs
很难过
来源: http://docs.aws .amazon.com/elasticbeanstalk/latest/dg/command-options-specific.html
一个可能的解决方案是我当前正在做的事情,在运行docker build之前,将一些文件添加到EB并从Dockerfile中使用它
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
示例,假设我在docker上需要一个变种名称TOKEN
,例如
example, lets assume I need a var name TOKEN
on my docker something like
RUN curl http://somemething.com?token=$TOKEN
所以我做的是
添加新的脚本文件
ADD ./curl-thing.sh /curl-thing.sh
和
if [ -f "./.env"]; then
source ./.env
fi
现在添加一个文件名.ebextensions/my-env.config
,该名称无关紧要,该名称存在于forlder .ebextensions上并具有扩展名.config
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
这篇关于Elastic Beanstalk和Dockerfile ARG指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!