Dockerfile 中的代码检查
本主题列出了 Dockerfile 中所有 JetBrains Rider 代码检查。
您可以在 编辑器 | 检查设置 | 检查严重性 | 其他语言 设置页面  Ctrl+Alt+S 上切换特定检查或更改其严重性级别。
检查 | 描述 | 默认严重性 |
|---|---|---|
JSON 数组格式中的单引号字符串 | 报告 JSON 数组格式中的单引号字符串。 JSON 数组格式中,必须使用双引号 (") 包围单词,而不是单引号 (')。 否则,Docker 构建将失败。 示例:
# all the commands below will fail
RUN ['/bin/bash', '-c', 'echo hello']
ADD ['binaryA.jar', 'binary2.jar', 'destination/']
COPY ['binaryA.jar', 'binary2.jar', 'destination/']
应用快速修复后:
RUN ["/bin/bash", "-c", "echo hello"]
ADD ["binaryA.jar", "binary2.jar", "destination/"]
COPY ["binaryA.jar", "binary2.jar", "destination/"]
| |
''ADD''/''COPY'' 命令的目标无效 | 报告 根据 Dockerfile 规范 ,如果指定了多个源,则目标必须是一个目录,并且必须以斜杠 '/' 结尾。 否则,Docker 构建将失败。 示例:
# all the commands below will fail
ADD textA.txt textB.txt relativeDir
ADD ["binaryA.jar", "binary2.jar", "destination"]
COPY text3.txt text4.txt /absolute/path
应用快速修复后:
ADD textA.txt textB.txt relativeDir/
ADD ["binaryA.jar", "binary2.jar", "destination/"]
COPY text3.txt text4.txt /absolute/path/
| |
''key=value'' 对中的空格无效 | 报告 虽然 Dockerfile 规范中未明确规定,但某些键值对的空格组合是不允许的。 Docker 构建在到达问题指令后将失败。 示例:
# all the commands below will fail
ARG answer = 42
ARG version= "1.0.0"
LABEL "maintained.by"= someone@gmail.com
ENV JAVA_HOME= "/docker-java-home"
应用快速修复后:
ARG answer=2
ARG version="1.0.0"
LABEL "maintained.by"=someone@gmail.com
ENV JAVA_HOME="/docker-java-home"
| |
''RUN'' 命令缺少续行符 | 报告 在 shell形式的 示例:
# the command below will fail
RUN /bin/bash -c 'source $HOME/.bashrc;
echo $HOME'
应用快速修复后:
RUN /bin/bash -c 'source $HOME/.bashrc; \
echo $HOME'
| |
参数数量错误 | 报告 Dockerfile 命令中参数数量无效。 Docker 构建在到达参数数量无效的指令后将失败。 |
最后修改日期: 2025年 9月 26日