Home Explore Blog CI



docker

1st chunk of `content/manuals/build/metadata/annotations.md`
f86ec09cab751339ea00df3175a798b50061c9c605a53ab50000000100000e87
---
title: Annotations
description: Annotations specify additional metadata about OCI images
keywords: build, buildkit, annotations, metadata
aliases:
- /build/building/annotations/
---

Annotations provide descriptive metadata for images. Use annotations to record
arbitrary information and attach it to your image, which helps consumers and
tools understand the origin, contents, and how to use the image.

Annotations are similar to, and in some sense overlap with, [labels]. Both
serve the same purpose: to attach metadata to a resource. As a general principle,
you can think of the difference between annotations and labels as follows:

- Annotations describe OCI image components, such as [manifests], [indexes],
  and [descriptors].
- Labels describe Docker resources, such as images, containers, networks, and
  volumes.

The OCI image [specification] defines the format of annotations, as well as a set
of pre-defined annotation keys. Adhering to the specified standards ensures
that metadata about images can be surfaced automatically and consistently, by
tools like Docker Scout.

Annotations are not to be confused with [attestations]:

- Attestations contain information about how an image was built and what it contains.
  An attestation is attached as a separate manifest on the image index.
  Attestations are not standardized by the Open Container Initiative.
- Annotations contain arbitrary metadata about an image.
  Annotations attach to the image [config] as labels,
  or on the image index or manifest as properties.

## Add annotations

You can add annotations to an image at build-time, or when creating the image
manifest or index.

> [!NOTE]
> 
> The Docker Engine image store doesn't support loading images with
> annotations. To build with annotations, make sure to push the image directly
> to a registry, using the `--push` CLI flag or the
> [registry exporter](/manuals/build/exporters/image-registry.md).

To specify annotations on the command line, use the `--annotation` flag for the
`docker build` command:

```console
$ docker build --push --annotation "foo=bar" .
```

If you're using [Bake](/manuals/build/bake/_index.md), you can use the `annotations`
attribute to specify annotations for a given target:

```hcl
target "default" {
  output = ["type=registry"]
  annotations = ["foo=bar"]
}
```

For examples on how to add annotations to images built with GitHub Actions, see
[Add image annotations with GitHub Actions](/manuals/build/ci/github-actions/annotations.md)

You can also add annotations to an image created using `docker buildx
imagetools create`. This command only supports adding annotations to an index
or manifest descriptors, see
[CLI reference](/reference/cli/docker/buildx/imagetools/create.md#annotation).

## Inspect annotations

To view annotations on an **image index**, use the `docker buildx imagetools
inspect` command. This shows you any annotations for the index and descriptors
(references to manifests) that the index contains. The following example shows
an `org.opencontainers.image.documentation` annotation on a descriptor, and an
`org.opencontainers.image.authors` annotation on the index.

```console {hl_lines=["10-12","19-21"]}
$ docker buildx imagetools inspect <IMAGE> --raw
{
  "schemaVersion": 2,
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "manifests": [
    {
      "mediaType": "application/vnd.oci.image.manifest.v1+json",
      "digest": "sha256:d20246ef744b1d05a1dd69d0b3fa907db007c07f79fe3e68c17223439be9fefb",
      "size": 911,
      "annotations": {
        "org.opencontainers.image.documentation": "https://foo.example/docs",
      },
      "platform": {
        "architecture": "amd64",
        "os": "linux"

Title: Understanding and Using Annotations in OCI Images
Summary
Annotations provide descriptive metadata for OCI images, similar to labels but specifically for image components like manifests and indexes. They help consumers and tools understand the image's origin and contents, adhering to OCI standards for consistent metadata surfacing. Annotations can be added during build-time using `docker build` or Bake, and inspected using `docker buildx imagetools inspect`. They should not be confused with attestations, which contain information about how an image was built and what it contains.