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,
Thanks Sushil
ARG instruction defines a variable that can be passed at build time. Once it is defined in the Dockerfile you can pass with this flag --build-arg while building the image. We can have multiple ARG instruction in the Dockerfile. ARG is the only instruction that can precede the FROM instruction in the Dockerfile.
From Dockerfile reference: The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg <varname>=<value> flag. The ENV instruction sets the environment variable <key> to the value <value> .
Running containers can't access values of ARG variables. This also applies to CMD and ENTRYPOINT instructions which just tell what the container should run by default.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With