How do I make a comment in a Dockerfile?

Better Stack Team
Updated on January 9, 2024

In a Dockerfile, you can add comments to provide information about the Dockerfile and the instructions in it. Comments in Dockerfiles start with the # symbol and continue to the end of the line.

For example, to add a comment explaining the purpose of a particular instruction in the Dockerfile, you can use the # symbol to add a comment like this:

 
# Install required packages
RUN apt-get update && apt-get install -y \
    package1 \
    package2 \
    package3

The comment in this example starts with the # symbol and continues to the end of the line. When the Dockerfile is built, the comments are ignored by the Docker daemon and do not affect the build process. Comments can be used to provide information about the Dockerfile, explain the purpose of individual instructions, or provide instructions for running the image.