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
ARG image=alpine
FROM $image
RUN echo $image
FROM $image
Given the above Dockerfile, hovering over the third line's $image variable will display the value alpine. You would think that to be the case. However, if you try to build the image, you will see that it is actually equivalent to an undeclared variable as nothing is echoed out.
$ docker build .
Sending build context to Docker daemon 86.15MB
Step 1/4 : ARG image=alpine
--->
Step 2/4 : FROM $image
latest: Pulling from library/alpine
88286f41530e: Pull complete
Digest: sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe
Status: Downloaded newer image for alpine:latest
---> 7328f6f8b418
Step 3/4 : RUN echo $image
---> Running in 45440aa2789c
---> e40554735702
Removing intermediate container 45440aa2789c
Step 4/4 : FROM $image
---> 7328f6f8b418
Successfully built 7328f6f8b418
moby/moby#34129 has a discussion about this somewhat confusing behaviour. The documentation states the following:
An ARG declared before a FROM is outside of a build stage, so it can't be used in any instruction after a FROM.
I think it's unlikely that the existing behaviour will be modified as existing Dockerfiles may be broken. We should fix how we resolve variables in our hover providers to account for this behaviour.
The text was updated successfully, but these errors were encountered:
It should be noted that ARG instructions that aren't at the top of the Dockerfile are scoped within a given build stage. The following example illustrates this as the final RUN echo $image instruction ends up printing nothing even though the same instruction on the 4th line did print something.
ARG image=alpine
FROM $image
ARG image=x
RUN echo $image
FROM $image
RUN echo $image
$ docker build .
Sending build context to Docker daemon 86.15MB
Step 1/6 : ARG image=alpine
--->
Step 2/6 : FROM $image
---> 7328f6f8b418
Step 3/6 : ARG image=x
---> Running in 1e5b1d7daf50
---> f8b94ce82721
Removing intermediate container 1e5b1d7daf50
Step 4/6 : RUN echo $image
---> Running in e52c161d1e16
x
---> e61f884cee2c
Removing intermediate container e52c161d1e16
Step 5/6 : FROM $image
---> 7328f6f8b418
Step 6/6 : RUN echo $image
---> Running in def5fca99fa1
---> 461c02d4735f
Removing intermediate container def5fca99fa1
Successfully built 461c02d4735f
rcjsuen
changed the title
ARG instructions declared before FROM makes their hovers invalid for regular instructions
ARG variables declared before the first FROM should only work with FROM instructions
Aug 23, 2017
We'll keep this issue to be solely about the effects of ARG instructions declared before the first FROM. The variable scoping issue described in the earlier comment will be covered by #163.
Given the above Dockerfile, hovering over the third line's
$image
variable will display the valuealpine
. You would think that to be the case. However, if you try to build the image, you will see that it is actually equivalent to an undeclared variable as nothing is echoed out.moby/moby#34129 has a discussion about this somewhat confusing behaviour. The documentation states the following:
I think it's unlikely that the existing behaviour will be modified as existing Dockerfiles may be broken. We should fix how we resolve variables in our hover providers to account for this behaviour.
The text was updated successfully, but these errors were encountered: