如何在docker中为详细信息指定注释

如何在docker中为详细信息指定注释,docker,dockerfile,Docker,Dockerfile,我在问如何在dockerfile中写评论。所以我需要明确我不是在谈论写作 #This is a comment 变成一个文件柜 我要找的是如何在详细描述中设置注释字段 docker inspect ubuntu -f {{.Comment}} docker inspect ubuntu 使用这两个命令之一,您可以在详细说明中看到注释条目。当前ubuntu容器的注释为空 我查了一下,没有发现任何关于它的东西。 我在谷歌上搜索了一下,发现堆积如山——不幸的是,关键字“comment”将搜索引向如

我在问如何在dockerfile中写评论。所以我需要明确我不是在谈论写作

#This is a comment
变成一个文件柜

我要找的是如何在详细描述中设置注释字段

docker inspect ubuntu -f {{.Comment}}
docker inspect ubuntu
使用这两个命令之一,您可以在详细说明中看到注释条目。当前ubuntu容器的注释为空

我查了一下,没有发现任何关于它的东西。 我在谷歌上搜索了一下,发现堆积如山——不幸的是,关键字“comment”将搜索引向如何使用
#comment
,这不是我想要的


我的问题是如何在详细描述中填充注释字段?

使用
docker commit
命令。见文件:


通常,这是为要管理的底层工具而保存的。这是以下内容的一部分:

您将在
docker image history
中看到该层历史,并且
docker image inspect
显示为从最后一层提取值

一些工具,如:

对于由经典的
docker build
命令构建的Dockerfile,我不知道如何在各个步骤上设置此注释字段

正如Rajesh所提到的,您可以使用
docker commit
命令设置注释,我不建议将该命令用于任何要投入生产的图像,因为图像需要以容易出错的方法手动创建


相反,向docker映像添加元数据的典型方法是设置一个

这些标签在从该图像生成时也会复制到容器元数据中,并且它们是从父图像继承的(在
from
行中设置),因此请确保替换子图像中的标签以避免混淆

$ docker pull nginx
$ docker image inspect -f {{.Comment}} nginx

$ docker run -d --name mycontainer nginx
$ docker commit -m "my comment" mycontainer nginx
$ docker image inspect -f {{.Comment}} nginx
my comment
// 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"`
}
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",
        })
    }
}
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."