Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Beanstalk and Dockerfile ARG instruction

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

like image 280
Sushil Avatar asked Sep 26 '16 08:09

Sushil


People also ask

How do I pass ARG in Dockerfile?

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.

What is Arg and ENV in 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> .

Can an ARG variable on Dockerfile be used by the running container?

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.


1 Answers

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

enter image description here

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
like image 186
rkmax Avatar answered Sep 23 '22 01:09

rkmax