| 1 |
## Output |
| 2 |
|
| 3 |
```text |
| 4 |
FROM --platform flag should not use constant value "linux/amd64" |
| 5 |
``` |
| 6 |
|
| 7 |
## Description |
| 8 |
|
| 9 |
Specifying `--platform` in the Dockerfile `FROM` instruction forces the image to build on only one target platform. This prevents building a multi-platform image from this Dockerfile and you must build on the same platform as specified in `--platform`. |
| 10 |
|
| 11 |
The recommended approach is to: |
| 12 |
|
| 13 |
* Omit `FROM --platform` in the Dockerfile and use the `--platform` argument on the command line. |
| 14 |
* Use `$BUILDPLATFORM` or some other combination of variables for the `--platform` argument. |
| 15 |
* Stage name should include the platform, OS, or architecture name to indicate that it only contains platform-specific instructions. |
| 16 |
|
| 17 |
## Examples |
| 18 |
|
| 19 |
❌ Bad: using a constant argument for `--platform` |
| 20 |
|
| 21 |
```dockerfile |
| 22 |
FROM --platform=linux/amd64 alpine AS base |
| 23 |
RUN apk add --no-cache git |
| 24 |
``` |
| 25 |
|
| 26 |
✅ Good: using the default platform |
| 27 |
|
| 28 |
```dockerfile |
| 29 |
FROM alpine AS base |
| 30 |
RUN apk add --no-cache git |
| 31 |
``` |
| 32 |
|
| 33 |
✅ Good: using a meta variable |
| 34 |
|
| 35 |
```dockerfile |
| 36 |
FROM --platform=${BUILDPLATFORM} alpine AS base |
| 37 |
RUN apk add --no-cache git |
| 38 |
``` |
| 39 |
|
| 40 |
✅ Good: used in a multi-stage build with a target architecture |
| 41 |
|
| 42 |
```dockerfile |
| 43 |
FROM --platform=linux/amd64 alpine AS build_amd64 |
| 44 |
... |
| 45 |
|
| 46 |
FROM --platform=linux/arm64 alpine AS build_arm64 |
| 47 |
... |
| 48 |
|
| 49 |
FROM build_${TARGETARCH} AS build |
| 50 |
... |
| 51 |
``` |