dockerapi-design

Docker: is not providing a default to ARG really "bad"?


Docker docs say that this is "bad":

ARG TAG
FROM busybox:${TAG}

Their rationale:

An ARG used in an image reference should be valid when no build arguments are used. An image build should not require --build-arg to be used to produce a valid build.

But isn't it preferable that a build would fail if the ARG was not explicitly provided? If one would follow their advice, then if the process of generating the desired TAG fails, a default image reference would be used, unbeknownst to the user.


Solution

  • A way to suppress the warning (that the snippet in OP would've raised) is to put a check at the top of Dockerfile:

    # syntax=docker/dockerfile:1
    # check=skip=InvalidDefaultArgInFrom