You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like I had missed a part of the specification in the Docker documentation. I had thought that ARG instructions at the top of the Dockerfile were completely disconnected from any ARG instruction after the first FROM. But it seems like you can actually use the default value defined by an ARG at the top of the Dockerfile if you simply redeclare an uninitialized ARG within a build stage.
An ARG declared before a FROM is outside of a build stage, so it can’t be used in any instruction after a FROM. To use the default value of an ARG declared before the first FROM use an ARG instruction without a value inside of a build stage:
ARG VERSION=latest
FROM busybox:$VERSION
ARG VERSION
RUN echo $VERSION > image_version
Because of this mistake, the following code will print out the wrong output.
It seems like I had missed a part of the specification in the Docker documentation. I had thought that
ARG
instructions at the top of the Dockerfile were completely disconnected from anyARG
instruction after the firstFROM
. But it seems like you can actually use the default value defined by anARG
at the top of the Dockerfile if you simply redeclare an uninitializedARG
within a build stage.Because of this mistake, the following code will print out the wrong output.
The first
RUN
instruction incorrectly resolves its$ver
variable reference to anull
.The same Dockerfile will echo out
latest
when built.The text was updated successfully, but these errors were encountered: