Browse code

builder: Update documentation WRT environment replacement

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)

Erik Hollensbe authored on 2014/10/28 05:05:29
Showing 1 changed files
... ...
@@ -104,6 +104,47 @@ be treated as an argument. This allows statements like:
104 104
 Here is the set of instructions you can use in a `Dockerfile` for building
105 105
 images.
106 106
 
107
+### Environment Replacement
108
+
109
+**Note:** prior to 1.3, `Dockerfile` environment variables were handled
110
+similarly, in that they would be replaced as described below. However, there
111
+was no formal definition on as to which instructions handled environment
112
+replacement at the time. After 1.3 this behavior will be preserved and
113
+canonical.
114
+
115
+Environment variables (declared with the `ENV` statement) can also be used in
116
+certain instructions as variables to be interpreted by the `Dockerfile`. Escapes
117
+are also handled for including variable-like syntax into a statement literally.
118
+
119
+Environment variables are notated in the `Dockerfile` either with
120
+`$variable_name` or `${variable_name}`. They are treated equivalently and the
121
+brace syntax is typically used to address issues with variable names with no
122
+whitespace, like `${foo}_bar`.
123
+
124
+Escaping is possible by adding a `\` before the variable: `\$foo` or `\${foo}`,
125
+for example, will translate to `$foo` and `${foo}` literals respectively.
126
+ 
127
+Example (parsed representation is displayed after the `#`):
128
+
129
+    FROM busybox
130
+    ENV foo /bar
131
+    WORKDIR ${foo}   # WORKDIR /bar
132
+    ADD . $foo       # ADD . /bar
133
+    COPY \$foo /quux # COPY $foo /quux
134
+
135
+The instructions that handle environment variables in the `Dockerfile` are:
136
+
137
+* `ENV`
138
+* `ADD`
139
+* `COPY`
140
+* `WORKDIR`
141
+* `EXPOSE`
142
+* `VOLUME`
143
+* `USER`
144
+
145
+`ONBUILD` instructions are **NOT** supported for environment replacement, even
146
+the instructions above.
147
+
107 148
 ## The `.dockerignore` file
108 149
 
109 150
 If a file named `.dockerignore` exists in the source repository, then it