How to Add OCI Labels to an Image in CI
Standard OCI labels record where an image came from, which commit built it, and when.
Let docker/metadata-action generate org.opencontainers.image.* labels, then pass its labels output to docker/build-push-action. You can also hardcode labels in the Dockerfile.
Steps
- Add
docker/metadata-actionto produce OCI labels. - Forward
steps.meta.outputs.labelsto the build step. - Optionally add static
LABELlines in the Dockerfile.
Workflow
.github/workflows/ci.yml
steps:
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}Dockerfile labels
Dockerfile
LABEL org.opencontainers.image.source="https://github.com/acme/app"
LABEL org.opencontainers.image.licenses="Apache-2.0"Related guides
How to Attach an SBOM and Provenance to an Image in CIGenerate and attach an SBOM and build provenance to a container image in GitHub Actions using the sbom and pr…
How to Tag Images by Git SHA, Semver, and Branch in CIGenerate consistent image tags in GitHub Actions with docker/metadata-action, deriving tags from the git SHA,…