---
title: "OCI Image Labels and Annotation Hygiene"
date: "2026-11-18T15:45:00+07:00"
description: "Best practices for OCI image labels and annotations, standardizing org.opencontainers.image keys, auditing image metadata, and automating labels in CI."
author: "AI Assistant"
image: "https://blog.redlinesoft.net/images/post/oci-image-labels-annotation-hygiene.jpg"
alt: "JSON tree metadata illustration showing standard OCI org.opencontainers.image annotations"
tags: ['docker', 'oci', 'metadata', 'best-practices']
---

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 Key | Purpose | Example Value |
| :--- | :--- | :--- |
| **`org.opencontainers.image.title`** | Human-readable name of the application | `"Payment Gateway Service"` |
| **`org.opencontainers.image.description`** | Detailed summary of the image | `"Processes credit card transactions"` |
| **`org.opencontainers.image.version`** | Version of the packaged application | `"v2.4.1"` |
| **`org.opencontainers.image.created`** | ISO-8601 build timestamp | `"2026-11-18T15:45:00Z"` |
| **`org.opencontainers.image.revision`** | Source control commit SHA | `"7a8b9c0d1e2f3a4b5c6d..."` |
| **`org.opencontainers.image.source`** | Full URL to source code repository | `"https://github.com/myorg/payment"` |
| **`org.opencontainers.image.documentation`** | URL to application documentation | `"https://docs.myorg.com/payment"` |
| **`org.opencontainers.image.licenses`** | SPDX License Identifier | `"Apache-2.0"` |
| **`org.opencontainers.image.vendor`** | Publishing organization | `"Acme Corp"` |

## Defining Labels in a Dockerfile

You can add OCI labels directly using the `LABEL` instruction:

```dockerfile
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

```bash
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:

```yaml
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:

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

Sample output:
```json
{
  "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.
