Skip to content
Blog

OCI Image Labels and Annotation Hygiene

Best practices for OCI image labels and annotations, standardizing org.opencontainers.image keys, auditing image metadata, and automating labels in CI.

Published on • November 18, 2026

AI Assistant

Container images are not just binary execution layers; they carry metadata defining authorship, source code repository URLs, build timestamps, license terms, and component versions. Historically, developers used arbitrary keys like LABEL maintainer="admin@example.com".

To standardize image metadata across registries, security scanners, and cloud platforms, the Open Container Initiative defined the OCI Image Index & Manifest Annotations Specification under the org.opencontainers.image namespace.

In this article, we will examine standard OCI label conventions, annotation hygiene best practices, and how to automate label injection in CI/CD pipelines.

OCI Standard Annotations (org.opencontainers.image)

The OCI specification defines standard keys for image metadata. Using these keys ensures your images render rich metadata automatically across Docker Hub, GitHub Packages, Harbor, and Kubernetes UI dashboards.

OCI Standard KeyPurposeExample Value
org.opencontainers.image.titleHuman-readable name of the application"Payment Gateway Service"
org.opencontainers.image.descriptionDetailed summary of the image"Processes credit card transactions"
org.opencontainers.image.versionVersion of the packaged application"v2.4.1"
org.opencontainers.image.createdISO-8601 build timestamp"2026-11-18T15:45:00Z"
org.opencontainers.image.revisionSource control commit SHA"7a8b9c0d1e2f3a4b5c6d..."
org.opencontainers.image.sourceFull URL to source code repository"https://github.com/myorg/payment"
org.opencontainers.image.documentationURL to application documentation"https://docs.myorg.com/payment"
org.opencontainers.image.licensesSPDX License Identifier"Apache-2.0"
org.opencontainers.image.vendorPublishing organization"Acme Corp"

Defining Labels in a Dockerfile

You can add OCI labels directly using the LABEL instruction:

FROM alpine:3.18

# Standardized OCI Image Metadata Labels
LABEL org.opencontainers.image.title="Payment Gateway API" \
      org.opencontainers.image.description="High-throughput payment processing service" \
      org.opencontainers.image.vendor="Acme Corporation" \
      org.opencontainers.image.licenses="Apache-2.0" \
      org.opencontainers.image.authors="devops@myorg.com"

WORKDIR /app
COPY payment-service /app/
CMD ["./payment-service"]

Automating Dynamic Labels in CI Pipelines

Hardcoding dynamic values like created timestamps or git revision hashes into Dockerfiles breaks layer caching. Instead, inject dynamic labels at build time using BuildKit arguments or CI metadata actions.

Injecting via Build Command

docker build \
  --label "org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
  --label "org.opencontainers.image.revision=$(git rev-parse HEAD)" \
  -t myorg/payment:v2.4.1 .

Automated Ingestion with GitHub Actions

Docker’s official docker/metadata-action automatically extracts Git tags, commit SHAs, PR numbers, and repository URLs, converting them into standard OCI labels:

name: Build Image with OCI Labels

on:
  push:
    tags:
      - 'v*'

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Extract OCI Metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: myregistry.com/myorg/payment
          labels: |
            org.opencontainers.image.vendor=Acme Corp
            org.opencontainers.image.licenses=Apache-2.0

      - name: Build and Push
        uses: docker/build-push-action@v5
        with:
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          push: true

Auditing Image Labels with docker inspect

To inspect the OCI labels attached to a built or pulled image:

docker inspect --format='{{json .Config.Labels}}' myregistry.com/myorg/payment:v2.4.1 | jq .

Sample output:

{
  "org.opencontainers.image.created": "2026-11-18T15:45:00Z",
  "org.opencontainers.image.description": "High-throughput payment processing service",
  "org.opencontainers.image.licenses": "Apache-2.0",
  "org.opencontainers.image.revision": "7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b",
  "org.opencontainers.image.source": "https://github.com/myorg/payment",
  "org.opencontainers.image.title": "Payment Gateway API",
  "org.opencontainers.image.vendor": "Acme Corporation",
  "org.opencontainers.image.version": "v2.4.1"
}

Rules for Metadata Hygiene

  1. Use org.opencontainers.image Prefix: Abandon legacy LABEL maintainer= or custom non-standard keys.
  2. Use Valid SPDX License Identifiers: Ensure image.licenses uses official SPDX codes (e.g. MIT, Apache-2.0, GPL-3.0-only).
  3. Never Put Secrets in Labels: Image labels are embedded in unencrypted JSON manifests visible to anyone who pulls the image. Never put passwords, API tokens, or internal credentials in labels.

Summary

Adopting standardized OCI labels improves container supply chain transparency, simplifies inventory management, and enables automated governance across cloud registries.