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?

  • Are Docker images full operating systems? Containers VS Virtual Machines
  • How to change Ruby and Rails version for the Rails base Docker image?
  • How to automate Grunt on a Docker image
  • Use gcloud with docker
  • Does docker stores all its files as “memory image”, as part of image, not disk file?
  • Is it possible to have Docker On VM?
  • Access host filesystem in the docker compose command
  • Xvfb command in docker supervisor conf not working
  • Push a Docker Compose to a Production Server
  • Increase the default disc space for Docker Images on macOS
  • Why removing docker containers and images does not free up storage space on Windows? How to fix it?
  • Integration Tests with Microservices (NodeJS), Jenkins and Docker
  • 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.