MultipleInstructionsDisallowed (不允许的多个指令)
目录
输出
Multiple CMD instructions should not be used in the same stage because only the last one will be used
描述
如果您的
Dockerfile 时,仅使用最后一个匹配项。镜像只能有一个 、 、 和 。CMD
HEALTHCHECK
ENTRYPOINT
CMD
HEALTHCHECK
ENTRYPOINT
例子
❌ 差:重复说明。
FROM alpine
ENTRYPOINT ["echo", "Hello, Norway!"]
ENTRYPOINT ["echo", "Hello, Sweden!"]
# Only "Hello, Sweden!" will be printed
✅ Good: 只有一条指令。ENTRYPOINT
FROM alpine
ENTRYPOINT ["echo", "Hello, Norway!\nHello, Sweden!"]
您可以同时为 Instruction(常规)、顶级和单独的指令。CMD
CMD
HEALTHCHECK
✅ Good: 只有一个顶级指令。CMD
FROM python:alpine
RUN apk add curl
HEALTHCHECK --interval=1s --timeout=3s \
CMD ["curl", "-f", "http://localhost:8080"]
CMD ["python", "-m", "http.server", "8080"]