How do I make a comment in a Dockerfile?

Better Stack Team
Updated on April 7, 2023

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.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack