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?

  • Docker image behaves different on different machines
  • No nodes connecting to host in docker swarm
  • amazon beans talk docker Failed to build Docker image aws_beanstalk/staging-app not a directory
  • initdb: could not change permissions of directory on Postgresql container
  • search on my Auth+TLS private docker registry
  • Bash restore database to a docker container for a WordPress + Piwik Solution
  • zeppelin can't communicate with Cassandra (docker, windows 10 host)
  • Remote debugging NodeJS in Docker with Visual Studio Code
  • Kubernetes multi-tier container application
  • GitLab local build using gitlab-runner
  • Rjava package installation freeze in a docker
  • docker exec TERM setting
  • 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.