Debian Codegraph @

buildkit/frontend/dockerfile/linter/docs/MultipleInstructionsDisallowed.md

raw
1 ## Output
2
3 ```text
4 Multiple CMD instructions should not be used in the same stage because only the last one will be used
5 ```
6
7 ## Description
8
9 If you have multiple `CMD`, `HEALTHCHECK`, or `ENTRYPOINT` instructions in your
10 Dockerfile, only the last occurrence is used. An image can only ever have one
11 `CMD`, `HEALTHCHECK`, and `ENTRYPOINT`.
12
13 ## Examples
14
15 ❌ Bad: Duplicate instructions.
16
17 ```dockerfile
18 FROM alpine
19 ENTRYPOINT ["echo", "Hello, Norway!"]
20 ENTRYPOINT ["echo", "Hello, Sweden!"]
21 # Only "Hello, Sweden!" will be printed
22 ```
23
24 ✅ Good: only one `ENTRYPOINT` instruction.
25
26 ```dockerfile
27 FROM alpine
28 ENTRYPOINT ["echo", "Hello, Norway!\nHello, Sweden!"]
29 ```
30
31 You can have both a regular, top-level `CMD`
32 and a separate `CMD` for a `HEALTHCHECK` instruction.
33
34 ✅ Good: only one top-level `CMD` instruction.
35
36 ```dockerfile
37 FROM python:alpine
38 RUN apk add curl
39 HEALTHCHECK --interval=1s --timeout=3s \
40 CMD ["curl", "-f", "http://localhost:8080"]
41 CMD ["python", "-m", "http.server", "8080"]
42 ```