docker/metadata-action: Generate Tags & Labels
metadata-action builds image tags and OCI labels from your Git context automatically.
Stop hand-writing tag logic. metadata-action turns branches, tags, SHAs, and semver into a tag set and labels, exposed as step outputs.
Key inputs (with:)
- images: base image name(s) to tag.
- tags: rules, e.g. type=semver,pattern={{version}}.
- labels: extra OCI labels to add.
- flavor: prefixes/suffixes and latest behavior.
Example workflow
.github/workflows/ci.yml
jobs:
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=sha
- uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}On any runner
metadata-action runs on any runner. Latchkey managed runners run it unchanged.
Key takeaways
- Feed steps.meta.outputs.tags into build-push-action.
- type=semver tags releases cleanly from Git tags.
- It also emits standard OCI labels for free.
Related guides
docker/build-push-action: Build & Push Images in CIReference for docker/build-push-action: build a Docker image with BuildKit and push it to a registry, with ta…
docker/login-action: Authenticate to a RegistryReference for docker/login-action: log in to Docker Hub, GHCR, ECR, or any registry before pushing images, wi…
docker/setup-buildx-action: Enable BuildKit in CIReference for docker/setup-buildx-action: create a Buildx builder so you can use BuildKit features, cache exp…