@@ -6,24 +6,25 @@ Usage of undefined variable '$foo'
66
77## Description
88
9- Before you reference an environment variable or a build argument in a ` RUN `
10- instruction, you should ensure that the variable is declared in the Dockerfile,
11- using the ` ARG ` or ` ENV ` instructions.
9+ This check ensures that environment variables and build arguments are correctly
10+ declared before being used. While undeclared variables might not cause an
11+ immediate build failure, they can lead to unexpected behavior or errors later
12+ in the build process.
1213
13- Attempting to access an environment variable without explicitly declaring it
14- doesn't necessarily result in a build error, but it may yield an unexpected
15- result or an error later on in the build process.
14+ This check does not evaluate undefined variables for ` RUN ` , ` CMD ` , and
15+ ` ENTRYPOINT ` instructions where you use the [ shell form] ( https://docs.docker.com/reference/dockerfile/#shell-form ) .
16+ That's because when you use shell form, variables are resolved by the command
17+ shell.
1618
17- This check also attempts to detect if you're accessing a variable with a typo.
18- For example, given the following Dockerfile:
19+ It also detects common mistakes like typos in variable names. For example, in
20+ the following Dockerfile:
1921
2022``` dockerfile
2123FROM alpine
2224ENV PATH=$PAHT:/app/bin
2325```
2426
25- The check detects that ` $PAHT ` is undefined, and that it's probably a
26- misspelling of ` PATH ` .
27+ The check identifies that ` $PAHT ` is undefined and likely a typo for ` $PATH ` :
2728
2829``` text
2930Usage of undefined variable '$PAHT' (did you mean $PATH?)
@@ -45,3 +46,17 @@ FROM alpine AS base
4546ARG foo
4647COPY $foo .
4748```
49+
50+ ❌ Bad: ` $foo ` is undefined.
51+
52+ ``` dockerfile
53+ FROM alpine AS base
54+ ARG VERSION=$foo
55+ ```
56+
57+ ✅ Good: the base image defines ` $PYTHON_VERSION `
58+
59+ ``` dockerfile
60+ FROM python AS base
61+ ARG VERSION=$PYTHON_VERSION
62+ ```
0 commit comments