Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit e0c2415

Browse files
Merge pull request #2620 from thaJeztah/19.03_backport_builder_comment_info
[19.03 backport] docs/builder: add note about handling of leading whitespace Upstream-commit: 18d6f8f6bfaad7d35133ca576d1547c8aa0f37bf Component: cli
2 parents d2a8fe0 + d0a8d03 commit e0c2415

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

components/cli/docs/reference/builder.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ be UPPERCASE to distinguish them from arguments more easily.
173173

174174

175175
Docker 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
177177
directives](#parser-directives), [comments](#format), and globally scoped
178178
[ARGs](#arg). The `FROM` instruction specifies the [*Parent
179179
Image*](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:
189189
RUN 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+
192207
Line 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
196240
Parser directives are optional, and affect the way in which subsequent lines

0 commit comments

Comments
 (0)