Signed-off-by: Kevin Burke <kev@inburke.com>
| ... | ... |
@@ -115,11 +115,11 @@ The instruction is not case-sensitive. However, convention is for them to |
| 115 | 115 |
be UPPERCASE to distinguish them from arguments more easily. |
| 116 | 116 |
|
| 117 | 117 |
|
| 118 |
-Docker runs instructions in a `Dockerfile` in order. **The first |
|
| 118 |
+Docker runs instructions in a `Dockerfile` in order. **The first |
|
| 119 | 119 |
instruction must be \`FROM\`** in order to specify the [*Base |
| 120 |
-Image*](glossary.md#base-image) from which you are building. |
|
| 120 |
+Image*](glossary.md#base-image) from which you are building. |
|
| 121 | 121 |
|
| 122 |
-Docker treats lines that *begin* with `#` as a comment, unless the line is |
|
| 122 |
+Docker treats lines that *begin* with `#` as a comment, unless the line is |
|
| 123 | 123 |
a valid [parser directive](builder.md#parser directives). A `#` marker anywhere |
| 124 | 124 |
else in a line is treated as an argument. This allows statements like: |
| 125 | 125 |
|
| ... | ... |
@@ -132,20 +132,20 @@ Line continuation characters are not supported in comments. |
| 132 | 132 |
|
| 133 | 133 |
## Parser directives |
| 134 | 134 |
|
| 135 |
-Parser directives are optional, and affect the way in which subsequent lines |
|
| 135 |
+Parser directives are optional, and affect the way in which subsequent lines |
|
| 136 | 136 |
in a `Dockerfile` are handled. Parser directives do not add layers to the build, |
| 137 | 137 |
and will not be shown as a build step. Parser directives are written as a |
| 138 | 138 |
special type of comment in the form `# directive=value`. A single directive |
| 139 | 139 |
may only be used once. |
| 140 | 140 |
|
| 141 |
-Once a comment, empty line or builder instruction has been processed, Docker |
|
| 141 |
+Once a comment, empty line or builder instruction has been processed, Docker |
|
| 142 | 142 |
no longer looks for parser directives. Instead it treats anything formatted |
| 143 | 143 |
as a parser directive as a comment and does not attempt to validate if it might |
| 144 | 144 |
be a parser directive. Therefore, all parser directives must be at the very |
| 145 |
-top of a `Dockerfile`. |
|
| 145 |
+top of a `Dockerfile`. |
|
| 146 | 146 |
|
| 147 | 147 |
Parser directives are not case-sensitive. However, convention is for them to |
| 148 |
-be lowercase. Convention is also to include a blank line following any |
|
| 148 |
+be lowercase. Convention is also to include a blank line following any |
|
| 149 | 149 |
parser directives. Line continuation characters are not supported in parser |
| 150 | 150 |
directives. |
| 151 | 151 |
|
| ... | ... |
@@ -166,7 +166,7 @@ Invalid due to appearing twice: |
| 166 | 166 |
|
| 167 | 167 |
FROM ImageName |
| 168 | 168 |
``` |
| 169 |
- |
|
| 169 |
+ |
|
| 170 | 170 |
Treated as a comment due to appearing after a builder instruction: |
| 171 | 171 |
|
| 172 | 172 |
```Dockerfile |
| ... | ... |
@@ -190,10 +190,10 @@ a comment which is not a parser directive. |
| 190 | 190 |
```Dockerfile |
| 191 | 191 |
# unknowndirective=value |
| 192 | 192 |
# knowndirective=value |
| 193 |
-``` |
|
| 194 |
- |
|
| 193 |
+``` |
|
| 194 |
+ |
|
| 195 | 195 |
Non line-breaking whitespace is permitted in a parser directive. Hence, the |
| 196 |
-following lines are all treated identically: |
|
| 196 |
+following lines are all treated identically: |
|
| 197 | 197 |
|
| 198 | 198 |
```Dockerfile |
| 199 | 199 |
#directive=value |
| ... | ... |
@@ -215,26 +215,26 @@ Or |
| 215 | 215 |
|
| 216 | 216 |
# escape=` (backtick) |
| 217 | 217 |
|
| 218 |
-The `escape` directive sets the character used to escape characters in a |
|
| 219 |
-`Dockerfile`. If not specified, the default escape character is `\`. |
|
| 218 |
+The `escape` directive sets the character used to escape characters in a |
|
| 219 |
+`Dockerfile`. If not specified, the default escape character is `\`. |
|
| 220 | 220 |
|
| 221 | 221 |
The escape character is used both to escape characters in a line, and to |
| 222 | 222 |
escape a newline. This allows a `Dockerfile` instruction to |
| 223 | 223 |
span multiple lines. Note that regardless of whether the `escape` parser |
| 224 |
-directive is included in a `Dockerfile`, *escaping is not performed in |
|
| 225 |
-a `RUN` command, except at the end of a line.* |
|
| 224 |
+directive is included in a `Dockerfile`, *escaping is not performed in |
|
| 225 |
+a `RUN` command, except at the end of a line.* |
|
| 226 | 226 |
|
| 227 |
-Setting the escape character to `` ` `` is especially useful on |
|
| 228 |
-`Windows`, where `\` is the directory path separator. `` ` `` is consistent |
|
| 227 |
+Setting the escape character to `` ` `` is especially useful on |
|
| 228 |
+`Windows`, where `\` is the directory path separator. `` ` `` is consistent |
|
| 229 | 229 |
with [Windows PowerShell](https://technet.microsoft.com/en-us/library/hh847755.aspx). |
| 230 | 230 |
|
| 231 |
-Consider the following example which would fail in a non-obvious way on |
|
| 231 |
+Consider the following example which would fail in a non-obvious way on |
|
| 232 | 232 |
`Windows`. The second `\` at the end of the second line would be interpreted as an |
| 233 |
-escape for the newline, instead of a target of the escape from the first `\`. |
|
| 233 |
+escape for the newline, instead of a target of the escape from the first `\`. |
|
| 234 | 234 |
Similarly, the `\` at the end of the third line would, assuming it was actually |
| 235 | 235 |
handled as an instruction, cause it be treated as a line continuation. The result |
| 236 | 236 |
of this dockerfile is that second and third lines are considered a single |
| 237 |
-instruction: |
|
| 237 |
+instruction: |
|
| 238 | 238 |
|
| 239 | 239 |
```Dockerfile |
| 240 | 240 |
FROM windowsservercore |
| ... | ... |
@@ -250,18 +250,18 @@ Results in: |
| 250 | 250 |
---> dbfee88ee9fd |
| 251 | 251 |
Step 2 : COPY testfile.txt c:RUN dir c: |
| 252 | 252 |
GetFileAttributesEx c:RUN: The system cannot find the file specified. |
| 253 |
- PS C:\John> |
|
| 253 |
+ PS C:\John> |
|
| 254 | 254 |
|
| 255 | 255 |
One solution to the above would be to use `/` as the target of both the `COPY` |
| 256 | 256 |
instruction, and `dir`. However, this syntax is, at best, confusing as it is not |
| 257 | 257 |
natural for paths on `Windows`, and at worst, error prone as not all commands on |
| 258 | 258 |
`Windows` support `/` as the path separator. |
| 259 | 259 |
|
| 260 |
-By adding the `escape` parser directive, the following `Dockerfile` succeeds as |
|
| 260 |
+By adding the `escape` parser directive, the following `Dockerfile` succeeds as |
|
| 261 | 261 |
expected with the use of natural platform semantics for file paths on `Windows`: |
| 262 | 262 |
|
| 263 | 263 |
# escape=` |
| 264 |
- |
|
| 264 |
+ |
|
| 265 | 265 |
FROM windowsservercore |
| 266 | 266 |
COPY testfile.txt c:\ |
| 267 | 267 |
RUN dir c:\ |
| ... | ... |
@@ -279,9 +279,9 @@ Results in: |
| 279 | 279 |
---> Running in a5ff53ad6323 |
| 280 | 280 |
Volume in drive C has no label. |
| 281 | 281 |
Volume Serial Number is 1440-27FA |
| 282 |
- |
|
| 282 |
+ |
|
| 283 | 283 |
Directory of c:\ |
| 284 |
- |
|
| 284 |
+ |
|
| 285 | 285 |
03/25/2016 05:28 AM <DIR> inetpub |
| 286 | 286 |
03/25/2016 04:22 AM <DIR> PerfLogs |
| 287 | 287 |
04/22/2016 10:59 PM <DIR> Program Files |
| ... | ... |
@@ -497,7 +497,7 @@ generated images. |
| 497 | 497 |
|
| 498 | 498 |
RUN has 2 forms: |
| 499 | 499 |
|
| 500 |
-- `RUN <command>` (*shell* form, the command is run in a shell, which by |
|
| 500 |
+- `RUN <command>` (*shell* form, the command is run in a shell, which by |
|
| 501 | 501 |
default is `/bin/sh -c` on Linux or `cmd /S /C` on Windows) |
| 502 | 502 |
- `RUN ["executable", "param1", "param2"]` (*exec* form) |
| 503 | 503 |
|
| ... | ... |
@@ -1209,7 +1209,7 @@ and for any `RUN`, `CMD` and `ENTRYPOINT` instructions that follow it in the |
| 1209 | 1209 |
|
| 1210 | 1210 |
The `WORKDIR` instruction sets the working directory for any `RUN`, `CMD`, |
| 1211 | 1211 |
`ENTRYPOINT`, `COPY` and `ADD` instructions that follow it in the `Dockerfile`. |
| 1212 |
-If the `WORKDIR` doesn't exist, it will be created even if its not used in any |
|
| 1212 |
+If the `WORKDIR` doesn't exist, it will be created even if it's not used in any |
|
| 1213 | 1213 |
subsequent `Dockerfile` instruction. |
| 1214 | 1214 |
|
| 1215 | 1215 |
It can be used multiple times in the one `Dockerfile`. If a relative path |
| ... | ... |
@@ -1548,7 +1548,7 @@ The `HEALTHCHECK` feature was added in Docker 1.12. |
| 1548 | 1548 |
## SHELL |
| 1549 | 1549 |
|
| 1550 | 1550 |
SHELL ["executable", "parameters"] |
| 1551 |
- |
|
| 1551 |
+ |
|
| 1552 | 1552 |
The `SHELL` instruction allows the default shell used for the *shell* form of |
| 1553 | 1553 |
commands to be overridden. The default shell on Linux is `["/bin/sh", "-c"]`, and on |
| 1554 | 1554 |
Windows is `["cmd", "/S", "/C"]`. The `SHELL` instruction *must* be written in JSON |
| ... | ... |
@@ -1558,21 +1558,21 @@ The `SHELL` instruction is particularly useful on Windows where there are |
| 1558 | 1558 |
two commonly used and quite different native shells: `cmd` and `powershell`, as |
| 1559 | 1559 |
well as alternate shells available including `sh`. |
| 1560 | 1560 |
|
| 1561 |
-The `SHELL` instruction can appear multiple times. Each `SHELL` instruction overrides |
|
| 1561 |
+The `SHELL` instruction can appear multiple times. Each `SHELL` instruction overrides |
|
| 1562 | 1562 |
all previous `SHELL` instructions, and affects all subsequent instructions. For example: |
| 1563 | 1563 |
|
| 1564 | 1564 |
FROM windowsservercore |
| 1565 |
- |
|
| 1566 |
- # Executed as cmd /S /C echo default |
|
| 1565 |
+ |
|
| 1566 |
+ # Executed as cmd /S /C echo default |
|
| 1567 | 1567 |
RUN echo default |
| 1568 |
- |
|
| 1569 |
- # Executed as cmd /S /C powershell -command Write-Host default |
|
| 1568 |
+ |
|
| 1569 |
+ # Executed as cmd /S /C powershell -command Write-Host default |
|
| 1570 | 1570 |
RUN powershell -command Write-Host default |
| 1571 |
- |
|
| 1571 |
+ |
|
| 1572 | 1572 |
# Executed as powershell -command Write-Host hello |
| 1573 | 1573 |
SHELL ["powershell", "-command"] |
| 1574 | 1574 |
RUN Write-Host hello |
| 1575 |
- |
|
| 1575 |
+ |
|
| 1576 | 1576 |
# Executed as cmd /S /C echo hello |
| 1577 | 1577 |
SHELL ["cmd", "/S"", "/C"] |
| 1578 | 1578 |
RUN echo hello |
| ... | ... |
@@ -1580,21 +1580,21 @@ all previous `SHELL` instructions, and affects all subsequent instructions. For |
| 1580 | 1580 |
The following instructions can be affected by the `SHELL` instruction when the |
| 1581 | 1581 |
*shell* form of them is used in a Dockerfile: `RUN`, `CMD` and `ENTRYPOINT`. |
| 1582 | 1582 |
|
| 1583 |
-The following example is a common pattern found on Windows which can be |
|
| 1584 |
-streamlined by using the `SHELL` instruction: |
|
| 1583 |
+The following example is a common pattern found on Windows which can be |
|
| 1584 |
+streamlined by using the `SHELL` instruction: |
|
| 1585 | 1585 |
|
| 1586 | 1586 |
... |
| 1587 | 1587 |
RUN powershell -command Execute-MyCmdlet -param1 "c:\foo.txt" |
| 1588 |
- ... |
|
| 1588 |
+ ... |
|
| 1589 | 1589 |
|
| 1590 | 1590 |
The command invoked by docker will be: |
| 1591 | 1591 |
|
| 1592 | 1592 |
cmd /S /C powershell -command Execute-MyCmdlet -param1 "c:\foo.txt" |
| 1593 |
- |
|
| 1593 |
+ |
|
| 1594 | 1594 |
This is inefficient for two reasons. First, there is an un-necessary cmd.exe command |
| 1595 | 1595 |
processor (aka shell) being invoked. Second, each `RUN` instruction in the *shell* |
| 1596 | 1596 |
form requires an extra `powershell -command` prefixing the command. |
| 1597 |
- |
|
| 1597 |
+ |
|
| 1598 | 1598 |
To make this more efficient, one of two mechanisms can be employed. One is to |
| 1599 | 1599 |
use the JSON form of the RUN command such as: |
| 1600 | 1600 |
|
| ... | ... |
@@ -1602,14 +1602,14 @@ use the JSON form of the RUN command such as: |
| 1602 | 1602 |
RUN ["powershell", "-command", "Execute-MyCmdlet", "-param1 \"c:\\foo.txt\""] |
| 1603 | 1603 |
... |
| 1604 | 1604 |
|
| 1605 |
-While the JSON form is unambiguous and does not use the un-necessary cmd.exe, |
|
| 1605 |
+While the JSON form is unambiguous and does not use the un-necessary cmd.exe, |
|
| 1606 | 1606 |
it does require more verbosity through double-quoting and escaping. The alternate |
| 1607 | 1607 |
mechanism is to use the `SHELL` instruction and the *shell* form, |
| 1608 |
-making a more natural syntax for Windows users, especially when combined with |
|
| 1608 |
+making a more natural syntax for Windows users, especially when combined with |
|
| 1609 | 1609 |
the `escape` parser directive: |
| 1610 |
- |
|
| 1610 |
+ |
|
| 1611 | 1611 |
# escape=` |
| 1612 |
- |
|
| 1612 |
+ |
|
| 1613 | 1613 |
FROM windowsservercore |
| 1614 | 1614 |
SHELL ["powershell","-command"] |
| 1615 | 1615 |
RUN New-Item -ItemType Directory C:\Example |
| ... | ... |
@@ -1628,16 +1628,16 @@ Resulting in: |
| 1628 | 1628 |
Removing intermediate container 87d7a64c9751 |
| 1629 | 1629 |
Step 3 : RUN New-Item -ItemType Directory C:\Example |
| 1630 | 1630 |
---> Running in 3e6ba16b8df9 |
| 1631 |
- |
|
| 1632 |
- |
|
| 1631 |
+ |
|
| 1632 |
+ |
|
| 1633 | 1633 |
Directory: C:\ |
| 1634 |
- |
|
| 1635 |
- |
|
| 1634 |
+ |
|
| 1635 |
+ |
|
| 1636 | 1636 |
Mode LastWriteTime Length Name |
| 1637 | 1637 |
---- ------------- ------ ---- |
| 1638 | 1638 |
d----- 6/2/2016 2:59 PM Example |
| 1639 |
- |
|
| 1640 |
- |
|
| 1639 |
+ |
|
| 1640 |
+ |
|
| 1641 | 1641 |
---> 1f1dfdcec085 |
| 1642 | 1642 |
Removing intermediate container 3e6ba16b8df9 |
| 1643 | 1643 |
Step 4 : ADD Execute-MyCmdlet.ps1 c:\example\ |
| ... | ... |
@@ -1654,7 +1654,7 @@ Resulting in: |
| 1654 | 1654 |
The `SHELL` instruction could also be used to modify the way in which |
| 1655 | 1655 |
a shell operates. For example, using `SHELL cmd /S /C /V:ON|OFF` on Windows, delayed |
| 1656 | 1656 |
environment variable expansion semantics could be modified. |
| 1657 |
- |
|
| 1657 |
+ |
|
| 1658 | 1658 |
The `SHELL` instruction can also be used on Linux should an alternate shell be |
| 1659 | 1659 |
required such `zsh`, `csh`, `tcsh` and others. |
| 1660 | 1660 |
|