kpi*_*pie 313 docker dockerfile
我正在写一个Dockerfile,我想知道是否有任何方法可以在这个文件中发表评论?docker是否有一个注释选项,它会占用剩下的一行并忽略它?
Ran*_*eet 414
您可以使用#来评论一条线.
# Everything on this line is a comment
Run Code Online (Sandbox Code Playgroud)
BMi*_*tch 78
正如其他人所提到的那样,注释用a引用#并在此处记录.但是,与某些语言不同,#必须在行的开头.如果它们在整个行中发生,它们将被解释为参数并可能导致意外行为.
# This is a comment
COPY test_dir target_dir # This is not a comment, it is an argument to COPY
RUN echo hello world # This is an argument to RUN but the shell may ignore it
Run Code Online (Sandbox Code Playgroud)
还应该注意,解析器指令最近已添加到Dockerfile中,其语法与注释相同.在任何其他注释或命令之前,它们需要出现在文件的顶部.目前,唯一的指令是更改转义字符以支持窗口:
# escape=`
FROM microsoft/nanoserver
COPY testfile.txt c:\
RUN dir c:\
Run Code Online (Sandbox Code Playgroud)
第一行虽然看起来是注释,但它是一个解析器指令,用于将转义字符更改为反引号,以便COPY和RUN命令可以使用路径中的反斜杠.
edh*_*tig 17
使用#注释语法
来自:https://docs.docker.com/engine/reference/builder/#format
# My comment here
RUN echo 'we are running some cool things'
Run Code Online (Sandbox Code Playgroud)
Dhr*_*hak 15
Dockerfile 注释以 开头#,就像 Python 一样。
ktaken 有很好的例子:
# Install a more-up-to date version of MongoDB than what is included in the default Ubuntu repositories.
FROM ubuntu
MAINTAINER Kimbro Staken
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
RUN echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | tee -a /etc/apt/sources.list.d/10gen.list
RUN apt-get update
RUN apt-get -y install apt-utils
RUN apt-get -y install mongodb-10gen
#RUN echo "" >> /etc/mongodb.conf
CMD ["/usr/bin/mongod", "--config", "/etc/mongodb.conf"]
Run Code Online (Sandbox Code Playgroud)
Docker 会将以开头的
#行视为注释,除非该行是有效的解析器指令。行中其他任何位置的标记#都被视为参数。示例代码:
Run Code Online (Sandbox Code Playgroud)# this line is a comment RUN echo 'we are running some # of cool things'输出:
Run Code Online (Sandbox Code Playgroud)we are running some # of cool things
| 归档时间: |
|
| 查看次数: |
109548 次 |
| 最近记录: |