Typically this is saved for the underlying tools to manage. It's part of the layer history spec:
// History describes the history of a layer.
type History struct {
// Created is the combined date and time at which the layer was created, formatted as defined by RFC 3339, section 5.6.
Created *time.Time `json:"created,omitempty"`
// CreatedBy is the command which created the layer.
CreatedBy string `json:"created_by,omitempty"`
// Author is the author of the build point.
Author string `json:"author,omitempty"`
// Comment is a custom message set when creating the layer.
Comment string `json:"comment,omitempty"`
// EmptyLayer is used to mark if the history item created a filesystem diff.
EmptyLayer bool `json:"empty_layer,omitempty"`
}
You'll see that layer history in the docker image history, and the docker image inspect appears to pull the value from the last layer.
Some tools like buildkit it gets set to a hardcoded value:
if len(diffs) > historyLayers {
// some history items are missing. add them based on the ref metadata
for _, md := range refMeta[historyLayers:] {
history = append(history, ocispec.History{
Created: &md.createdAt,
CreatedBy: md.description,
Comment: "buildkit.exporter.image.v0",
})
}
}
With a Dockerfile built by the classic docker build command, I'm not aware of any way to set this Comment field on the individual steps.
As mentioned by Rajesh, you can set the comment with the docker commit command which I don't recommend using for any images going to production since the image needs to be manually created in an error prone method.
Instead, the typical way to add metadata to a docker image is to set a label in the Dockefile.
LABEL "com.example.vendor"="ACME Incorporated"
LABEL com.example.label-with-value="foo"
LABEL version="1.0"
LABEL description="This text illustrates \
that label-values can span multiple lines."
These labels are also copied into the container metadata when it's spawned from that image, and they are inherited from the parent image (set in your FROM line) so be sure to replace the label in child images to avoid confusion.