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?

  • kubernetes : PTY allocation request failed
  • How to use docker with mongo to achieve replication and with opening authentication
  • Docker mongodb - add database on disk to container
  • Laravel MySQL Error ONLY on Scheduled Tasks (via cron)
  • How to setup Docker for a polyglot microservice-based application?
  • Is there a way to tell kubernetes to update your containers?
  • Recursive error shown by docker daemon
  • ubuntu automatic stop a daemon doesnt happening
  • How to parameterize Dockerfile?
  • Why does the tag appear to be tightly coupled to hostname of the registry?
  • Django on Docker - relation “django_session” does not exist at character 109
  • Docker compose share environment variables
  • 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

    Use the # 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 COPY and 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 --recv 7F0CEB10
    RUN echo "deb 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"] 
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.