Skip to content

Commit 92e37b2

Browse files
authored
Merge pull request moby#5451 from dvdksn/check-jsonargs-recommend
docs: add workarounds for JSONArgsRecommended check
2 parents 0836ac6 + a302dd1 commit 92e37b2

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

frontend/dockerfile/docs/rules/json-args-recommended.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,41 @@ Note that running programs as PID 1 means the program now has the special
5050
responsibilities and behaviors associated with PID 1 in Linux, such as reaping
5151
child processes.
5252

53-
Alternatively, if you want to ignore this lint rule because you do want your
54-
executable to be invoked via a shell, you can use the
55-
[`SHELL`](https://docs.docker.com/reference/dockerfile/#shell) Dockerfile
56-
instruction to explicitly specify a shell to use.
53+
### Workarounds
54+
55+
There might still be cases when you want to run your containers under a shell.
56+
When using exec form, shell features such as variable expansion, piping (`|`)
57+
and command chaining (`&&`, `||`, `;`), are not available. To use such
58+
features, you need to use shell form.
59+
60+
Here are some ways you can achieve that. Note that this still means that
61+
executables run as child-processes of a shell.
62+
63+
#### Create a wrapper script
64+
65+
You can create an entrypoint script that wraps your startup commands, and
66+
execute that script with a JSON-formatted `ENTRYPOINT` command.
67+
68+
✅ Good: the `ENTRYPOINT` uses JSON format.
69+
70+
```dockerfile
71+
FROM alpine
72+
RUN apk add bash
73+
COPY --chmod=755 <<EOT /entrypoint.sh
74+
#!/usr/bin/env bash
75+
set -e
76+
my-background-process &
77+
my-program start
78+
EOT
79+
ENTRYPOINT ["/entrypoint.sh"]
80+
```
81+
82+
#### Explicitly specify the shell
83+
84+
You can use the [`SHELL`](https://docs.docker.com/reference/dockerfile/#shell)
85+
Dockerfile instruction to explicitly specify a shell to use. This will suppress
86+
the warning since setting the `SHELL` instruction indicates that using shell
87+
form is a conscious decision.
5788

5889
✅ Good: shell is explicitly defined.
5990

frontend/dockerfile/linter/docs/JSONArgsRecommended.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,41 @@ Note that running programs as PID 1 means the program now has the special
4343
responsibilities and behaviors associated with PID 1 in Linux, such as reaping
4444
child processes.
4545

46-
Alternatively, if you want to ignore this lint rule because you do want your
47-
executable to be invoked via a shell, you can use the
48-
[`SHELL`](https://docs.docker.com/reference/dockerfile/#shell) Dockerfile
49-
instruction to explicitly specify a shell to use.
46+
### Workarounds
47+
48+
There might still be cases when you want to run your containers under a shell.
49+
When using exec form, shell features such as variable expansion, piping (`|`)
50+
and command chaining (`&&`, `||`, `;`), are not available. To use such
51+
features, you need to use shell form.
52+
53+
Here are some ways you can achieve that. Note that this still means that
54+
executables run as child-processes of a shell.
55+
56+
#### Create a wrapper script
57+
58+
You can create an entrypoint script that wraps your startup commands, and
59+
execute that script with a JSON-formatted `ENTRYPOINT` command.
60+
61+
✅ Good: the `ENTRYPOINT` uses JSON format.
62+
63+
```dockerfile
64+
FROM alpine
65+
RUN apk add bash
66+
COPY --chmod=755 <<EOT /entrypoint.sh
67+
#!/usr/bin/env bash
68+
set -e
69+
my-background-process &
70+
my-program start
71+
EOT
72+
ENTRYPOINT ["/entrypoint.sh"]
73+
```
74+
75+
#### Explicitly specify the shell
76+
77+
You can use the [`SHELL`](https://docs.docker.com/reference/dockerfile/#shell)
78+
Dockerfile instruction to explicitly specify a shell to use. This will suppress
79+
the warning since setting the `SHELL` instruction indicates that using shell
80+
form is a conscious decision.
5081

5182
✅ Good: shell is explicitly defined.
5283

0 commit comments

Comments
 (0)