Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print ARG value in docker build

Is there a way to print ARGs values, that are passed via the --build-arg flags to a docker build command?

Just using RUN echo $ARG_NAME isn't enough since I want it to be printed before the FROM section, where it's not allowed.

The point is to see these values immediately so I can stop the build quickly, preventing downloading the wrong base images.

Already searched docker docs and google. Maybe someone here can shed some light.

like image 521
yair Avatar asked Mar 02 '23 09:03

yair


1 Answers

You could use a multi-stage build where the first stage is just for diagnostics and otherwise gets completely ignored.

FROM busybox
ARG ARG_NAME
RUN echo $ARG_NAME

FROM python:3.8
ARG ARG_NAME
...
CMD ["my_app"]

Note that Docker layer caching can cause RUN steps to be totally skipped so even this isn't 100% reliable.

like image 171
David Maze Avatar answered Mar 05 '23 19:03

David Maze