patternMinor
Why can this ENV not be found when it is defined in one layer using a Dockerfile?
Viewed 0 times
thiswhycanlayerfoundonedockerfileusingwhenenv
Problem
When the following Dockerfile:
is run, it results in:
When two
it works:
ENV A=123 \
B=$A
RUN echo $Bis run, it results in:
Step 2/2 : RUN echo $B
---> Running in x
---> y
Removing intermediate container zWhen two
ENV layers are defined:ENV A=123
ENV B=$Ait works:
Step 2/2 : RUN echo $B
---> Running in x
123
---> y
Removing intermediate container zSolution
The
What happens here is that when the shell parse the line to give it to
Step by step this will give:
On the second form, A is available to the shell when the line is parsed, and as such the resulting
ENV keyword will be translated to export command (builin of the shell usually), if you remove the multi-line declaration you end up with this equivalent:export A=123 B=$AWhat happens here is that when the shell parse the line to give it to
export input, A is not yet exported and available as an environment variable.Step by step this will give:
- You type
export A=123 B=$A
- The shell parse the line and pass
A=123 B=toexport's stdin
exportparse each argument in the formkey=valueand as such exportAto be123andBto be empty
On the second form, A is available to the shell when the line is parsed, and as such the resulting
export's stdin is B=123Code Snippets
export A=123 B=$AContext
StackExchange DevOps Q#666, answer score: 3
Revisions (0)
No revisions yet.