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?

  • How kubelet - docker container communication happens?
  • Laravel installed on a local volume (Mac) from docker nginx/php-fpm can't write session files
  • curl can get web content hosted in local docker but browser cannot open the page
  • Basic Docker container reports runlevel unknown
  • From inside the docker container i want to copy the file in to the host machine
  • “device or resource busy” error when trying to push image with docker
  • Docker for Jobs
  • Unable to pull docker image - Repository not found
  • Docker maven plugin NullPointerException
  • Can FreeBSD be run inside Docker?
  • Docker user Permission denied on accessing folder in container
  • How do I avoid download images on all docker hosts which are part of my swarm?
  • 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.