@@ -6,24 +6,25 @@ Usage of undefined variable '$foo'
6
6
7
7
## Description
8
8
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.
12
13
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.
16
18
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:
19
21
20
22
``` dockerfile
21
23
FROM alpine
22
24
ENV PATH=$PAHT:/app/bin
23
25
```
24
26
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 ` :
27
28
28
29
``` text
29
30
Usage of undefined variable '$PAHT' (did you mean $PATH?)
@@ -45,3 +46,17 @@ FROM alpine AS base
45
46
ARG foo
46
47
COPY $foo .
47
48
```
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