| 1 |
## Output |
| 2 |
|
| 3 |
```text |
| 4 |
Using the global ARGs with default values should produce a valid build. |
| 5 |
``` |
| 6 |
|
| 7 |
## Description |
| 8 |
|
| 9 |
An `ARG` used in an image reference should be valid when no build arguments are used. An image build should not require `--build-arg` to be used to produce a valid build. |
| 10 |
|
| 11 |
## Examples |
| 12 |
|
| 13 |
❌ Bad: don't rely on an ARG being set for an image reference to be valid |
| 14 |
|
| 15 |
```dockerfile |
| 16 |
ARG TAG |
| 17 |
FROM busybox:${TAG} |
| 18 |
``` |
| 19 |
|
| 20 |
✅ Good: include a default for the ARG |
| 21 |
|
| 22 |
```dockerfile |
| 23 |
ARG TAG=latest |
| 24 |
FROM busybox:${TAG} |
| 25 |
``` |
| 26 |
|
| 27 |
✅ Good: ARG can be empty if the image would be valid with it empty |
| 28 |
|
| 29 |
```dockerfile |
| 30 |
ARG VARIANT |
| 31 |
FROM busybox:stable${VARIANT} |
| 32 |
``` |
| 33 |
|
| 34 |
✅ Good: Use a default value if the build arg is not present |
| 35 |
|
| 36 |
```dockerfile |
| 37 |
ARG TAG |
| 38 |
FROM alpine:${TAG:-3.14} |
| 39 |
``` |