如何在Dockerfile中发表评论?

我正在写一个Dockerfile,我想知道是否有任何方式在这个文件中发表评论? docker工人有一个评论选项,其余的一行,并忽略它?

您可以使用#来评论一行 。

# Everything on this line is a comment 

使用#语法进行注释

来自: https : //docs.docker.com/engine/reference/builder/#format

 # My comment here RUN echo 'we are running some cool things' 

正如其他人所提到的,评论是用#引用的, 在这里有logging 。 但是,与一些语言不同, #必须在行首。 如果它们发生在部分路线中,则它们被解释为参数,并可能导致意外的行为。

 # This is a comment COPY test_dir target_dir # this is not a comment, it is an arg to COPY RUN echo hello world # this is an argument to RUN but the shell may ignore it 

还应该注意的是,最近已经将parsing器指令添加到与注释语法相同的Dockerfile中。 他们需要出现在文件的顶部,在任何其他评论或命令之前。 目前,唯一的指令是改变转义字符来支持windows:

 # escape=` FROM microsoft/nanoserver COPY testfile.txt c:\ RUN dir c:\ 

第一行虽然看起来是一个注释,但它是一个parsing器指令,用于将转义字符更改为反引号,以便COPYRUN命令可以在path中使用反斜线。

Dockerfile的注释就像python一样以'#'开头。 这是一个很好的例子: https : //github.com/kstaken/dockerfile-examples/blob/master/mongodb/Dockerfile

 # Install a more up to date 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"]