How do I make a comment in a Dockerfile?
I am writing a Dockerfile and I want to know if there is any way to make comments in this file? Does docker have a comment option that takes the rest of a line and ignores it?
4 Solutions collect form web for “How do I make a comment in a Dockerfile?”
You can use # to comment a line.
# Everything on this line is a comment
# syntax for comments
# My comment here RUN echo 'we are running some cool things'
As others have mentioned, comments are referenced with a
# and are documented here. However, unlike some languages, the
# must be at the beginning of the line. If they occur part way through the line, they are interpreted as an argument and may result in unexpected behavior.
# 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
It should also be noted that parser directives have recently been added to the Dockerfile which have the same syntax as a comment. They need to appear at the top of the file, before any other comments or commands. At present, the only directive is for changing the escape character to support windows:
# escape=` FROM microsoft/nanoserver COPY testfile.txt c:\ RUN dir c:\
The first line, while it appears to be a comment, is a parser directive to change the escape character to a backtick so that the
RUN commands can use the backslash in the path.
Dockerfile comments start with ‘#’ just like python.
Here is a good example :
# 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"]