Reputation: 129
lets start by example. I have a simple Dockerfile:
ARG arg1
ARG arg2
RUN echo "$arg1 $arg2"
And what i expect when i call the command
docker build --build-arg arg1=abc --build-arg arg2=${arg1} .
Is that i got the abc abc as the outbut, but i got abc. So is the result that i want possible? And how can I achieve it?
Upvotes: 1
Views: 1282
Reputation: 6828
Do this in your Dockerfile
FROM alpine
ARG arg1
ARG arg2
RUN
echo "$arg1 ${arg2:-$arg1}"
You can now call it like this:
docker build --build-arg arg1=abc --build-arg arg2= .
output:
...truncated...
Step 4/4 : RUN echo "$arg1 ${arg2:-$arg1}"
---> Running in e65458b9ba6e
abc abc
or like this:
docker build --build-arg arg1=abc --build-arg arg2=override .
output:
...truncated...
Step 4/4 : RUN echo "$arg1 ${arg2:-$arg1}"
---> Running in e65458b9ba6e
abc override
(old answer)
Based on the little info you've provided. I would say:
arg1=abc; docker build --build-arg arg1=$arg1 --build-arg arg2=$arg1
should give you what you want.
Upvotes: 1