Add docs for multi-stage builds
| ... | ... |
@@ -480,30 +480,36 @@ the first pattern, followed by one or more `!` exception patterns. |
| 480 | 480 |
|
| 481 | 481 |
## FROM |
| 482 | 482 |
|
| 483 |
- FROM <image> |
|
| 483 |
+ FROM <image> [AS <name>] |
|
| 484 | 484 |
|
| 485 | 485 |
Or |
| 486 | 486 |
|
| 487 |
- FROM <image>:<tag> |
|
| 487 |
+ FROM <image>[:<tag>] [AS <name>] |
|
| 488 | 488 |
|
| 489 | 489 |
Or |
| 490 | 490 |
|
| 491 |
- FROM <image>@<digest> |
|
| 491 |
+ FROM <image>[@<digest>] [AS <name>] |
|
| 492 | 492 |
|
| 493 |
-The `FROM` instruction sets the [*Base Image*](glossary.md#base-image) |
|
| 494 |
-for subsequent instructions. As such, a valid `Dockerfile` must have `FROM` as |
|
| 495 |
-its first instruction. The image can be any valid image – it is especially easy |
|
| 496 |
-to start by **pulling an image** from the [*Public Repositories*](https://docs.docker.com/engine/tutorials/dockerrepos/). |
|
| 493 |
+The `FROM` instruction initializes a new build stage and sets the |
|
| 494 |
+[*Base Image*](glossary.md#base-image) for subsequent instructions. As such, a |
|
| 495 |
+valid `Dockerfile` must have `FROM` as its first instruction. The image can be |
|
| 496 |
+any valid image – it is especially easy to start by **pulling an image** from |
|
| 497 |
+the [*Public Repositories*](https://docs.docker.com/engine/tutorials/dockerrepos/). |
|
| 497 | 498 |
|
| 498 | 499 |
- `FROM` must be the first non-comment instruction in the `Dockerfile`. |
| 499 | 500 |
|
| 500 |
-- `FROM` can appear multiple times within a single `Dockerfile` in order to create |
|
| 501 |
-multiple images. Simply make a note of the last image ID output by the commit |
|
| 502 |
-before each new `FROM` command. |
|
| 501 |
+- `FROM` can appear multiple times within a single `Dockerfile` in order to |
|
| 502 |
+create multiple images or use one build stage as a dependency for another. |
|
| 503 |
+Simply make a note of the last image ID output by the commit before each new |
|
| 504 |
+`FROM` command. Each `FROM` command resets all the previous commands. |
|
| 503 | 505 |
|
| 504 |
-- The `tag` or `digest` values are optional. If you omit either of them, the builder |
|
| 505 |
-assumes a `latest` by default. The builder returns an error if it cannot match |
|
| 506 |
-the `tag` value. |
|
| 506 |
+- Optionally a name can be given to a new build stage. That name can be then |
|
| 507 |
+used in subsequent `FROM` and `COPY --from=<name|index>` commands to refer back |
|
| 508 |
+to the image built in this stage. |
|
| 509 |
+ |
|
| 510 |
+- The `tag` or `digest` values are optional. If you omit either of them, the |
|
| 511 |
+builder assumes a `latest` tag by default. The builder returns an error if it |
|
| 512 |
+cannot match the `tag` value. |
|
| 507 | 513 |
|
| 508 | 514 |
## RUN |
| 509 | 515 |
|
| ... | ... |
@@ -937,6 +943,13 @@ All new files and directories are created with a UID and GID of 0. |
| 937 | 937 |
> If you build using STDIN (`docker build - < somefile`), there is no |
| 938 | 938 |
> build context, so `COPY` can't be used. |
| 939 | 939 |
|
| 940 |
+Optionally `COPY` accepts a flag `--from=<name|index>` that can be used to set |
|
| 941 |
+the source location to a previous build stage (created with `FROM .. AS <name>`) |
|
| 942 |
+that will be used instead of a build context sent by the user. The flag also |
|
| 943 |
+accepts a numeric index assigned for all previous build stages started with |
|
| 944 |
+`FROM` command. In case a build stage with a specified name can't be found an |
|
| 945 |
+image with the same name is attempted to be used instead. |
|
| 946 |
+ |
|
| 940 | 947 |
`COPY` obeys the following rules: |
| 941 | 948 |
|
| 942 | 949 |
- The `<src>` path must be inside the *context* of the build; |