Docking Argument

How to pass arguments to docker file?

Suppose I have a docker file:

FROM ubuntu:14.04 MAINTAINER Karl Morrison sudo do-something-here myVarHere 

I would like to create a file like this:

 docker build basickarl/my-image-example /directory/of/my/dockerfile "my string to be passed to myVarHere here!" 
+6
source share
2 answers

Docker has ARG , which you can use here

 FROM ubuntu:14.04 MAINTAINER Karl Morrison ARG myVarHere RUN do-something-here myVarHere 

And then create with --build-arg :

 docker build --build-arg myVarHere=value 
+5
source

We had a similar requirement and a relatively simple script came up that does just that:

We create a file called dockerfile_template , in which we use the variables in the same way as you describe. the script accepts this file, performs string replacements, and copies it to dockerfile (no _template) before calling docker build dockerfile .

It works very well. Also very expandable for future needs.

Update :

Drop it. Use build-arg ( here )

+2
source

All Articles