Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker build argument

How does one pass arguments into a dockerfile?

Lets say I have the dockerfile:

FROM    ubuntu:14.04

MAINTAINER Karl Morrison

sudo do-something-here myVarHere

I would want to build the file as so for example:

docker build basickarl/my-image-example /directory/of/my/dockerfile "my string to be passed to myVarHere here!"
like image 313
basickarl Avatar asked Dec 09 '15 08:12

basickarl


2 Answers

Docker has ARG that you can use here

FROM    ubuntu:14.04

MAINTAINER Karl Morrison

ARG myVarHere

RUN do-something-here myVarHere

And then build using --build-arg:

docker build --build-arg myVarHere=value
like image 108
manojlds Avatar answered Nov 09 '22 07:11

manojlds


We've had a similar requirement and came up with a relatively simple script that does exactly that:

We create a file called dockerfile_template in which we use variables just like you describe. The script takes that file, performs string substitutions and copies it to dockerfile (no _template) before calling docker build dockerfile.

Works pretty good. Also very extensible for future requirements.

Update:

Scrap that. Use build-arg (here)

like image 43
Jan Groth Avatar answered Nov 09 '22 06:11

Jan Groth