14

I am calling the docker build command from a shell script and I wanna pass an array in the build args .. First question can I really do that ? If yes then how do i iterate inside the docker file. A Small example will really help.

2 Answers 2

14

You can pass a space-separated string to builds then convert string to an array or just loop over the string.

Dockerfile

FROM alpine
ARG items
RUN for item in $items; do \
    echo "$item"; \
    done;

pass value during build time

docker build --build-arg items="item1 item2 item3 item4" -t my_image .

output

Step 3/3 : RUN for item in $items; do     echo "$item";     done;
 ---> Running in bee1fd1dd3c6
item1
item2
item3
Sign up to request clarification or add additional context in comments.

Comments

-3

You can use the keyword ARG RELEASE=master inside the Dockerfile and and then pass the argument at the time of docker build as --build-arg RELEASE=v0.1.0.

The below link give you completed example of the same.

https://blog.dockbit.com/making-use-of-docker-build-arguments-68792d751f3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.