【Docker】Dockerfile 格式
参考教程:https://docs.docker.com/engine/reference/builder/
环境
- virtual box 6.1
- centos 7.8
- docker 19.03
格式
Here is the format of the Dockerfile
:
这是 Dockerfile 的格式:
# Comment
INSTRUCTION arguments
The instruction is not case-sensitive. However, convention is for them to be UPPERCASE to distinguish them from arguments more easily.
指令不区分大小写。但是,按约定将它们大写,以便更轻松地将它们与参数区分开。
Docker runs instructions in a Dockerfile
in order. A Dockerfile
must begin with a FROM
instruction. This may be after parser directives, comments, and globally scoped ARGs. The FROM
instruction specifies the Parent Image from which you are building. FROM
may only be preceded by one or more ARG
instructions, which declare arguments that are used in FROM
lines in the Dockerfile
.
Docker 依次运行在 Dockerfile 中的指令。Dockerfile 必须以 FROM 指令开头。这可能在parser directives,注释和全局范围内的 ARG 之后。FROM
指令指定基础镜像。在 FROM 之前只能有一个或多个 ARG 指令,这些指令声明在 Dockerfile 的 FROM 行中使用的参数。
Docker treats lines that begin with #
as a comment, unless the line is a valid parser directive. A #
marker anywhere else in a line is treated as an argument. This allows statements like:
除非该行是有效的 parser directives,否则 Docker 会将以 #
号开头的行作为注释。一行中其他任何地方的 #
标记都被视为参数。这允许如下语句:
# Comment
RUN echo 'we are running some # of cool things'
Comment lines are removed before the Dockerfile instructions are executed, which means that the comment in the following example is not handled by the shell executing the echo
command, and both examples below are equivalent:
在执行 Dockerfile 指令之前会删除注释行,这意味着以下示例中的注释不会由执行echo
命令的 shell 处理,并且以下两个示例是等效的:
RUN echo hello \
# comment
world
RUN echo hello \
world
Line continuation characters are not supported in comments.
注释中不支持换行符。
空格注意事项
For backward compatibility, leading whitespace before comments (#
) and instructions (such as RUN
) are ignored, but discouraged. Leading whitespace is not preserved in these cases, and the following examples are therefore equivalent:
为了向后兼容,注释(#
)和指令(例如 RUN
)之前的空格将被忽略,但不鼓励使用。在这些情况下,不保留前导空格,因此以下示例是等效的:
# this is a comment-line
RUN echo hello
RUN echo world
# this is a comment-line
RUN echo hello
RUN echo world
Note however, that whitespace in instruction arguments, such as the commands following RUN
, are preserved, so the following example prints ` hello world` with leading whitespace as specified:
但是请注意,指令参数中的空格(例如 RUN
命令之后的空格)被保留,因此以下示例使用指定的前导空格打印` hello world`:
RUN echo "\
hello\
world
总结
介绍了 Dockerfile 的格式。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2019-11-29 FileSystemResource 找不到文件