skip to content

What does an OCI registry do when a push asks to mount a blob from another repository instead of uploading it?

level: middleimportance: should knowfreq 30%

answer

  1. blobs belong to a repository
  2. a POST that carries no bytes
  3. mount= and from= query parameters
  4. 201 versus 202

basics

~20 s

If it supports mounting and can find the blob, the registry links the existing blob into the target repository and answers 201 Created without receiving any bytes. Otherwise it answers 202 Accepted and opens an ordinary upload session instead.

solid answer

~40 s

In the distribution API every blob is reached through a repository: `/v2/<name>/blobs/<digest>`. When a push to `team/api` needs a blob that already exists in `base/runtime` on the same registry, the client sends `POST /v2/team/api/blobs/uploads/?mount=<digest>&from=base/runtime` in place of starting an upload. A registry that mounts it answers `201 Created` with a `Location` for the blob in the target repository: no bytes travel, and with content-addressed storage one stored copy can serve both repositories. A registry that does not support mounting, or cannot mount that blob, should answer `202 Accepted`, which means an upload session has started and the client uploads normally. The spec lets a registry treat `from` as optional. The open-source registry's API documentation describes the source as a repository the client has read access to.

code

http · 6 lines
http
POST /v2/team/api/blobs/uploads/?mount=sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0&from=base/runtime
Content-Length: 0

HTTP/1.1 201 Created
Location: /v2/team/api/blobs/sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0
Docker-Content-Digest: sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0

go deeper

for a junior

Recall that blobs live in repositories and that a mount reuses a blob already in the registry instead of uploading it again.

for a middle

Explain the mount request, the 201 and 202 outcomes, and why blobs are pushed before the manifest that lists them.

for a senior

Reason about the permission check on the source repository, why a mount never crosses registries, and why deleting a mounted blob frees no disk until garbage collection.

for a principal

Use repository layout and shared base images deliberately, so mounts save bandwidth and storage without blurring the permission boundaries between teams.

## Why a blob has to be mounted at all The OCI distribution specification scopes every API call to a **repository**, the `<name>` in `/v2/<name>/...`. A blob is fetched at `/v2/<name>/blobs/<digest>`, and a `HEAD` on that path answers for *that* repository: it can return `404 Not Found` even when the same bytes sit in another repository on the same registry. Underneath, registries store content by **digest**, so identical bytes need only one stored copy. The spec's own use case says that when two uploads of the same layer race, "the registry may securely only store one copy of the layer since the computed digests match". A **cross-repository blob mount** connects the two facts: it asks the registry to make an existing stored blob part of another repository, without the client sending it again. Typical cases: - many service images built on one shared base image in `base/runtime`; - copying or promoting content between repositories of the same registry; - an artifact such as an SBOM pushed into several repositories. ## The push sequence around a mount A push uploads blobs first and the manifest last: 1. For each blob the manifest will list, check whether the target repository already has it with `HEAD /v2/<name>/blobs/<digest>`. 2. If it is missing but known to exist in another repository of the same registry, request a mount; otherwise start an upload with `POST /v2/<name>/blobs/uploads/`. 3. When every blob is present, `PUT /v2/<name>/manifests/<tag-or-digest>`. A registry may reject a manifest that references blobs it does not hold with `MANIFEST_BLOB_UNKNOWN`, which is why the manifest goes last. ## The request and its two outcomes The mount request is `POST /v2/<name>/blobs/uploads/?mount=<digest>&from=<other_name>`, where `<name>` is the **target** repository and `<other_name>` the **source**. The registry answers one of two ways: | Response | What it means | What the client does next | |---|---|---| | `201 Created` with `Location` | The blob is now available in the target repository | Nothing more for this blob | | `202 Accepted` with `Location` | Mount unsupported or not possible; an upload session has begun | Upload the blob to the returned location | Details worth knowing: - A mount that cannot happen is **not an error**. The `202` fallback keeps the client working against registries that do not recognise the mount parameters, which already answer this way. - Because `202` covers both "not supported" and "blob not there", a client that needs to know which can `HEAD` the blob in the source repository first, as the open-source registry's API documentation suggests. - The registry **may treat `from` as optional** and mount the blob from wherever it finds it. - A mount works only **within one registry**. Copying content to a different registry always uploads the blobs the target lacks. ## Storage and access consequences - **No new copy.** A mounted blob typically costs no new storage; the registry records that another repository now refers to the stored bytes. - **Access control still applies.** Repositories are the unit of permission, and a digest is not a secret: it appears in manifests, logs and build output. The open-source registry's API documentation describes a mount as coming from a repository the client has read access to. A registry that mounted any blob by digest regardless of permissions would leak private layers into a repository its owner can read. - **Deletes are per repository.** Where the registry enables it, `DELETE /v2/<name>/blobs/<digest>` removes the blob from that repository's view. The bytes stay on disk while anything else references them, and are reclaimed only by the registry's garbage collection. ## Reading a push that mounted From the outside a mount is easy to miss, so it helps to know what each side records: - The client sends a `POST` with `Content-Length: 0` and no body; the only evidence of the blob is the digest in the query string. - The registry's `Location` header on a `201` names the blob under the **target** repository, and the `Docker-Content-Digest` header returns the blob's digest, which a careful client checks against what it expected. - A push that falls back to `202` then shows the ordinary upload traffic: `PATCH` requests for chunks, or a single `PUT` with `?digest=` that closes the session with `201 Created`. - If uploads of a large shared base layer are seen on every push of every service, the mount is not happening: the source repository may be unreadable to the pushing identity, the source name may be wrong, or the registry may not support mounting at all. ## Takeaways - Mounting is a server-side link, not a transfer; it turns content addressing into saved bandwidth and storage. - `201` means done, `202` means upload as usual; a well-behaved client handles both. - It never crosses registries and should never cross a permission boundary.

  • Why should a registry check permissions on the source repository before mounting?
    Repositories are the unit of access control, and digests are not secrets: they appear in public manifests, logs and build output. If a registry mounted any blob whose digest matched, someone who learned the digest of a private layer could pull it into a repository they can read. The open-source registry's API documentation describes mounts as coming from a repository the client can read.
  • What happens to storage when the target repository later deletes a mounted blob?
    Where the registry enables blob deletion, the delete removes the blob from that repository's view and returns 202 Accepted. The bytes stay stored while another repository or manifest still references them. In the open-source registry, garbage collection removes a blob from storage only once no manifest refers to it.
  • Does a cross-repository mount help when copying an image between two registries?
    No. A mount links content within one registry. Copying to another registry uploads every blob the target lacks, although a HEAD check before each upload skips blobs the target already holds.

  • A mount that cannot be done fails the push with an error.
  • A blob mount copies the bytes into new storage for the target repository.
  • Mounting works between two different registries if both follow the OCI spec.
  • Anyone who knows a digest can mount that blob from any repository.
  • The manifest is uploaded first so the registry knows which blobs to expect.