8

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.

yair
  • 8,945
  • 4
  • 31
  • 50

2 Answers2

11

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.

David Maze
  • 130,717
  • 29
  • 175
  • 215
0

This is not possible

A Dockerfile must begin with a FROM instruction

see https://docs.docker.com/engine/reference/builder/

The execution of the RUN command will be performed in an intermediate container that has to be created of an image.

RoBeaToZ
  • 1,113
  • 10
  • 18
  • Thanks for the answer :). I'm aware of that. That's why I mentioned I can't use `RUN echo....`. I was wondering whether there's some other way / workaround, maybe some verbosity level... – yair Jun 07 '20 at 20:23
  • 2
    Sorry but a Dockerfile may not start with FROM instruction since it is possible to pass the base image as a build variable. In this case, Dockerfile will start with ARG VARNAME, then FROM VARNAME. https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact – breakthewall Jul 08 '20 at 13:44