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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github