basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Pin images by digest: tags move, hashes don’t

    A Docker image tag (traefik:v3.7, postgres:16, latest) is a label that the registry or image author can repoint to a different build without changing the name. Appending @sha256:… (the digest) makes Docker pull the exact set of layers you tested, and a new build under the same tag won't land on the server without editing the Compose file.

    Why a tag doesn’t pin an image

    A tag in a registry (Docker Hub, GHCR) is a pointer to a manifest, and it can be overwritten. latest changes on every new build, and version tags such as postgres:16 or nginx:1.29 also shift when the base image is rebuilt or a patch release drops (1.29.2 to 1.29.3). Even an exact patch tag (v3.7.1) can be rebuilt by the author under the same name.

    In practice, that hits in two ways:

    • moving to a new VPS, docker compose up -d pulls a newer build under the same tag, and the service may behave differently;
    • if an author’s account is compromised and a tampered build is pushed under an existing tag, the next docker compose pull installs it silently.

    A digest is the SHA-256 hash of the image manifest (sha256:…). Change a single byte in a layer or config and the digest changes.

    How to write and look up a digest

    In docker-compose.yaml (and in FROM inside a Dockerfile), append the digest with @ right after the tag:

    services:
      traefik:
        image: traefik:v3.7@sha256:4d5b6e...

    Keep the tag before @ for humans and update tools so you can read the version at a glance. When pulling and starting the container, Docker looks only at @sha256:… and ignores the tag in front of it.

    Two ways to get the digest:

    docker image inspect traefik:v3.7 --format '{{index .RepoDigests 0}}'
    # traefik@sha256:4d5b6e...
    • straight from the registry without pulling — this also guarantees you get the top-level multi-arch manifest digest:
    docker buildx imagetools inspect traefik:v3.7 | grep '^Digest:'
    # Digest:        sha256:4d5b6e...

    Maintaining dozens of digests by hand gets tedious. When server configs live in git, let Renovate with the docker:pinDigests preset handle them: it appends @sha256:… to tags and opens a weekly pull request with updated builds (Deploy without SSH).

    When to pin by digest and when a tag is enough

    On a production server where configs live in git and updates go through pull requests, pin images by digest: every commit records the exact stack state, and a rollback restores the exact same build. For a quick experiment or local sandbox, a minor-version tag (traefik:v3.7) is enough — pinning only slows down switching between versions.

    If it doesn’t work

    You changed the tag (traefik:v3.7 to v3.8), yet Docker keeps running the old version

    Cause
    The old @sha256:… is still on the image: line: when a digest is present, Docker pulls by digest and ignores the tag before @.
    Fix
    Update both the tag and the digest together, or temporarily strip @sha256:… to fetch the new digest for the target tag.

    manifest unknown or no matching manifest for linux/arm64 after copying a digest from another machine

    Cause
    You copied a single-architecture build digest (such as amd64) instead of the top-level multi-arch manifest, or the old build was removed from the registry.
    Fix
    Get the top-level manifest digest via docker buildx imagetools inspect <image:tag> — it lists every supported architecture.

    docker image inspect prints an empty RepoDigests

    Cause
    The image was built locally (docker build) and never pushed to a registry, so it has no registry digest.
    Fix
    Push your image to a registry (GitHub Actions to GHCR); once pushed and pulled, the digest is available.

    How to check

    Compare the digest in docker-compose.yaml against what is pulled and running:

    docker image inspect traefik:v3.7@sha256:<digest> --format '{{index .RepoDigests 0}}'
    # traefik@sha256:<digest>
    docker compose config --hash '*'

    If RepoDigests matches the line in docker-compose.yaml and docker compose up -d does not recreate the container (The compose config hash), the service is running the exact pinned build.