@@ -173,7 +173,7 @@ be UPPERCASE to distinguish them from arguments more easily.
173173
174174
175175Docker runs instructions in a ` Dockerfile ` in order. A ` Dockerfile ` ** must
176- begin with a \ ` FROM\ ` instruction** . This may be after [ parser
176+ begin with a ` FROM ` instruction** . This may be after [ parser
177177directives] ( #parser-directives ) , [ comments] ( #format ) , and globally scoped
178178[ ARGs] ( #arg ) . The ` FROM ` instruction specifies the [ * Parent
179179Image* ] ( https://docs.docker.com/glossary/#parent_image ) from which you are
@@ -189,8 +189,52 @@ else in a line is treated as an argument. This allows statements like:
189189RUN echo 'we are running some # of cool things'
190190```
191191
192+ Comment lines are removed before the Dockerfile instructions are executed, which
193+ means that the comment in the following example is not handled by the shell
194+ executing the ` echo ` command, and both examples below are equivalent:
195+
196+ ``` dockerfile
197+ RUN echo hello \
198+ # comment
199+ world
200+ ```
201+
202+ ``` dockerfile
203+ RUN echo hello \
204+ world
205+ ```
206+
192207Line continuation characters are not supported in comments.
193208
209+ > ** Note on whitespace**
210+ >
211+ > For backward compatibility, leading whitespace before comments (` # ` ) and
212+ > instructions (such as ` RUN ` ) are ignored, but discouraged. Leading whitespace
213+ > is not preserved in these cases, and the following examples are therefore
214+ > equivalent:
215+ >
216+ > ``` dockerfile
217+ > # this is a comment-line
218+ > RUN echo hello
219+ > RUN echo world
220+ > ```
221+ >
222+ > ```dockerfile
223+ > # this is a comment-line
224+ > RUN echo hello
225+ > RUN echo world
226+ > ```
227+ >
228+ > Note however, that whitespace in instruction _arguments_, such as the commands
229+ > following `RUN`, are preserved, so the following example prints ` hello world`
230+ > with leading whitespace as specified:
231+ >
232+ > ```dockerfile
233+ > RUN echo "\
234+ > hello\
235+ > world"
236+ > ```
237+
194238# # Parser directives
195239
196240Parser directives are optional, and affect the way in which subsequent lines
0 commit comments