Skip to content

[core][sandbox] Support a Docker Hub pull-through mirror - #65745

Merged
pcmoritz merged 9 commits into
ray-project:masterfrom
xyuzh:sandbox-registry-mirror
Sep 1, 2026
Merged

pcmoritz merged 9 commits into
ray-project:masterfrom
xyuzh:sandbox-registry-mirror

Conversation

@xyuzh

@xyuzh xyuzh commented Aug 26, 2026

Copy link
Copy Markdown
Member

Why are these changes needed?

Sandbox image pulls are anonymous Docker Hub pulls. A cluster of nodes pulling distinct multi-GB benchmark images concurrently runs straight into Docker Hub's anonymous rate limits and pays WAN latency on every node — during a Terminal-Bench 2.1 evaluation under Harbor, big-image tasks failed in the concurrent sweep but passed in isolation.

RAY_SANDBOX_REGISTRY_MIRROR names a registry that mirrors Docker Hub, as host[:port][/repo-prefix]:

  • an ECR pull-through cache (<acct>.dkr.ecr.<region>.amazonaws.com/dockerhub),
  • an Artifact Registry remote repository, or
  • an in-cluster registry:2 proxy.

Docker Hub pulls are rewritten to the mirror (the prefix prepended to the repository, as ECR requires); other registries pass through untouched. This mirrors Docker's own registry-mirrors semantics, minus the fallback: when set, the mirror is authoritative, and it uses the same anonymous token flow as any registry.

Related issue number

Follow-up to #65570; sibling of #65737 and #65744.

Checks

  • Signed off (DCO); pre-commit hooks pass on the changed files.
  • Unit test included (test_registry_mirror_rewrites_docker_hub_only); runs without gVisor or network.

Sandbox image pulls are anonymous Docker Hub pulls, so a fleet of
nodes pulling benchmark images concurrently runs straight into Docker
Hub's anonymous rate limits and pays WAN latency per node.

RAY_SANDBOX_REGISTRY_MIRROR names a registry that mirrors Docker Hub
as host[:port][/repo-prefix] — an ECR pull-through cache, an Artifact
Registry remote repository, or an in-cluster registry:2 proxy — and
Docker Hub pulls are rewritten to it (other registries pass through
untouched). Mirrors Docker's own registry-mirrors semantics, minus the
fallback: when set, the mirror is authoritative.

Signed-off-by: xyuzh <[email protected]>
@xyuzh
xyuzh requested a review from a team as a code owner August 26, 2026 16:53

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for routing Docker Hub pulls through a configured pull-through mirror using the RAY_SANDBOX_REGISTRY_MIRROR environment variable. It adds the apply_registry_mirror helper function to rewrite registry and repository paths for Docker Hub, updates the image pulling logic to apply this mirror, and includes corresponding unit tests. Feedback suggests handling potential scheme prefixes (like http:// or https://) in the mirror URL to prevent malformed host and prefix partitioning, along with adding a test case to verify this behavior.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit b78668e. Configure here.

@pcmoritz

Copy link
Copy Markdown
Contributor

This looks great to me, some thoughts:

  1. We should add a section in the documentation about this, maybe with a real example of how this can be configured
  2. It would be good to see how it fits into existing conventions for specifying mirrors, is there any docker reference we can reference in the docs that this is similar to? Is it possible to specify multiple mirrors / what are the upstream conventions about that?

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core labels Aug 26, 2026
@xyuzh
xyuzh force-pushed the sandbox-registry-mirror branch from b2b8332 to f4460a2 Compare August 28, 2026 00:30
Review feedback: in-cluster pull-through proxies (a plain registry:2)
speak HTTP, and a scheme-prefixed mirror value previously produced
broken https://http://... URLs. An explicit http:// or https:// scheme
on RAY_SANDBOX_REGISTRY_MIRROR is now parsed and honored; bare hosts
keep the https default.

Signed-off-by: xyuzh <[email protected]>
@pcmoritz pcmoritz added the go add ONLY when ready to merge, run all tests label Aug 31, 2026

@pcmoritz pcmoritz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, can you fix the merge conflict @xyuzh and we can get this merged!

pcmoritz and others added 2 commits August 31, 2026 14:13
Add a Container images section covering how sandbox images are pulled
and cached, and a subsection for RAY_SANDBOX_REGISTRY_MIRROR: why a
concurrent cluster needs a mirror, the host[:port][/repo-prefix] value
with worked examples for ECR pull-through caches, Artifact Registry
remote repositories, and an in-cluster registry:2 proxy, plus the three
behaviors that surprise: HTTPS by default, no fallback to Docker Hub,
and anonymous pulls only. Point the image-pull troubleshooting bullet at
it.

Signed-off-by: xyuzh <[email protected]>
@xyuzh
xyuzh requested a review from a team as a code owner August 31, 2026 22:25
@xyuzh
xyuzh requested a review from pcmoritz August 31, 2026 23:06
@xyuzh

xyuzh commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

docs updated

Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
@pcmoritz
pcmoritz enabled auto-merge (squash) September 1, 2026 01:56
@pcmoritz
pcmoritz merged commit 167681c into ray-project:master Sep 1, 2026
7 checks passed
pcmoritz added a commit that referenced this pull request Sep 6, 2026
#65748)

## Why are these changes needed?

Nodes cache the extracted rootfs of every image they ever ran **plus an
uncompressed re-tar of it**, and nothing reclaims the space. A
long-lived node eventually fills its disk, which takes down far more
than sandboxes: during Terminal-Bench 2.1 sweeps (89 distinct images,
many multi-GB) under Harbor, aged nodes degraded into opaque 500s from
the whole Ray stack while fresh nodes ran the same images fine.

Changes:

- **The image cache is bounded by default.** Before each pull,
`ImageManager` evicts the least recently extracted images until the
cache fits the cap. The cap defaults to half of the filesystem that
holds the cache; `RAY_SANDBOX_IMAGE_CACHE_MAX_BYTES` sets it explicitly
and `0` disables eviction. Sibling and orphan `<name>.tar` archives
count toward the cap.
- **Images in use are pinned through `ImageManager`.** `pull_image(...,
instance_id=)` registers the sandbox as a user of the image while
holding the image's lock, and `release_image(image, instance_id)` drops
the pin. Eviction re-checks users under the same lock, so a pull can
never race an eviction, and mid-pull images (no `.extracted` marker) and
images whose lock is held are skipped. The gVisor backend pins on pull,
releases on every creation-failure path, and releases after teardown in
`delete_sandbox`, once the overlay's lower layer is unused. Backends
built on `BaseImageManager` get this for free.
- **The uncompressed tarball is gone.** Its only reader was a restore
branch that re-extracted it when the extracted directory had
disappeared, which nothing exercised, and it doubled every image's disk
footprint. Archives left by earlier versions count toward the cap and
are evicted with their image.

`RAY_SANDBOX_IMAGE_CACHE_MAX_BYTES` is documented in the sandboxes guide
under "Container images" and in the troubleshooting section.

## Related issue number

Follow-up to #65570; sibling of #65737 / #65744 / #65745 (the
Terminal-Bench fix series).

## Checks

- [x] Signed off (DCO); `ruff`, `black`, and `pydoclint` pass with the
pre-commit versions and flags.
- [x] Unit tests run without gVisor: `test_image_cache_eviction` (LRU
order, in-use and kept images protected, unextracted skipped, orphan
tarballs counted), `test_pull_pins_image_until_release` (pin on pull and
on cache hit, eviction blocked until release),
`test_image_cache_max_bytes_default_and_env`. The gVisor-gated
remote-pull test asserts no archive is written.

---------

Signed-off-by: xyuzh <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: Philipp Moritz <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…#65745)

## Why are these changes needed?

Sandbox image pulls are anonymous Docker Hub pulls. A cluster of nodes
pulling distinct multi-GB benchmark images concurrently runs straight
into Docker Hub's anonymous rate limits and pays WAN latency on every
node — during a Terminal-Bench 2.1 evaluation under Harbor, big-image
tasks failed in the concurrent sweep but passed in isolation.

`RAY_SANDBOX_REGISTRY_MIRROR` names a registry that mirrors Docker Hub,
as `host[:port][/repo-prefix]`:

- an **ECR pull-through cache**
(`<acct>.dkr.ecr.<region>.amazonaws.com/dockerhub`),
- an **Artifact Registry remote repository**, or
- an in-cluster `registry:2` proxy.

Docker Hub pulls are rewritten to the mirror (the prefix prepended to
the repository, as ECR requires); other registries pass through
untouched. This mirrors Docker's own `registry-mirrors` semantics, minus
the fallback: when set, the mirror is authoritative, and it uses the
same anonymous token flow as any registry.

## Related issue number

Follow-up to ray-project#65570; sibling of ray-project#65737 and ray-project#65744.

## Checks

- [x] Signed off (DCO); pre-commit hooks pass on the changed files.
- [ ] Unit test included
(`test_registry_mirror_rewrites_docker_hub_only`); runs without gVisor
or network.

---------

Signed-off-by: xyuzh <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: Philipp Moritz <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
ray-project#65748)

## Why are these changes needed?

Nodes cache the extracted rootfs of every image they ever ran **plus an
uncompressed re-tar of it**, and nothing reclaims the space. A
long-lived node eventually fills its disk, which takes down far more
than sandboxes: during Terminal-Bench 2.1 sweeps (89 distinct images,
many multi-GB) under Harbor, aged nodes degraded into opaque 500s from
the whole Ray stack while fresh nodes ran the same images fine.

Changes:

- **The image cache is bounded by default.** Before each pull,
`ImageManager` evicts the least recently extracted images until the
cache fits the cap. The cap defaults to half of the filesystem that
holds the cache; `RAY_SANDBOX_IMAGE_CACHE_MAX_BYTES` sets it explicitly
and `0` disables eviction. Sibling and orphan `<name>.tar` archives
count toward the cap.
- **Images in use are pinned through `ImageManager`.** `pull_image(...,
instance_id=)` registers the sandbox as a user of the image while
holding the image's lock, and `release_image(image, instance_id)` drops
the pin. Eviction re-checks users under the same lock, so a pull can
never race an eviction, and mid-pull images (no `.extracted` marker) and
images whose lock is held are skipped. The gVisor backend pins on pull,
releases on every creation-failure path, and releases after teardown in
`delete_sandbox`, once the overlay's lower layer is unused. Backends
built on `BaseImageManager` get this for free.
- **The uncompressed tarball is gone.** Its only reader was a restore
branch that re-extracted it when the extracted directory had
disappeared, which nothing exercised, and it doubled every image's disk
footprint. Archives left by earlier versions count toward the cap and
are evicted with their image.

`RAY_SANDBOX_IMAGE_CACHE_MAX_BYTES` is documented in the sandboxes guide
under "Container images" and in the troubleshooting section.

## Related issue number

Follow-up to ray-project#65570; sibling of ray-project#65737 / ray-project#65744 / ray-project#65745 (the
Terminal-Bench fix series).

## Checks

- [x] Signed off (DCO); `ruff`, `black`, and `pydoclint` pass with the
pre-commit versions and flags.
- [x] Unit tests run without gVisor: `test_image_cache_eviction` (LRU
order, in-use and kept images protected, unextracted skipped, orphan
tarballs counted), `test_pull_pins_image_until_release` (pin on pull and
on cache hit, eviction blocked until release),
`test_image_cache_max_bytes_default_and_env`. The gVisor-gated
remote-pull test asserts no archive is written.

---------

Signed-off-by: xyuzh <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: Philipp Moritz <[email protected]>
pawelbeza pushed a commit to pawelbeza/ray that referenced this pull request Oct 23, 2026
…#65745)

## Why are these changes needed?

Sandbox image pulls are anonymous Docker Hub pulls. A cluster of nodes
pulling distinct multi-GB benchmark images concurrently runs straight
into Docker Hub's anonymous rate limits and pays WAN latency on every
node — during a Terminal-Bench 2.1 evaluation under Harbor, big-image
tasks failed in the concurrent sweep but passed in isolation.

`RAY_SANDBOX_REGISTRY_MIRROR` names a registry that mirrors Docker Hub,
as `host[:port][/repo-prefix]`:

- an **ECR pull-through cache**
(`<acct>.dkr.ecr.<region>.amazonaws.com/dockerhub`),
- an **Artifact Registry remote repository**, or
- an in-cluster `registry:2` proxy.

Docker Hub pulls are rewritten to the mirror (the prefix prepended to
the repository, as ECR requires); other registries pass through
untouched. This mirrors Docker's own `registry-mirrors` semantics, minus
the fallback: when set, the mirror is authoritative, and it uses the
same anonymous token flow as any registry.

## Related issue number

Follow-up to ray-project#65570; sibling of ray-project#65737 and ray-project#65744.

## Checks

- [x] Signed off (DCO); pre-commit hooks pass on the changed files.
- [ ] Unit test included
(`test_registry_mirror_rewrites_docker_hub_only`); runs without gVisor
or network.

---------

Signed-off-by: xyuzh <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: Philipp Moritz <[email protected]>
pawelbeza pushed a commit to pawelbeza/ray that referenced this pull request Oct 23, 2026
ray-project#65748)

## Why are these changes needed?

Nodes cache the extracted rootfs of every image they ever ran **plus an
uncompressed re-tar of it**, and nothing reclaims the space. A
long-lived node eventually fills its disk, which takes down far more
than sandboxes: during Terminal-Bench 2.1 sweeps (89 distinct images,
many multi-GB) under Harbor, aged nodes degraded into opaque 500s from
the whole Ray stack while fresh nodes ran the same images fine.

Changes:

- **The image cache is bounded by default.** Before each pull,
`ImageManager` evicts the least recently extracted images until the
cache fits the cap. The cap defaults to half of the filesystem that
holds the cache; `RAY_SANDBOX_IMAGE_CACHE_MAX_BYTES` sets it explicitly
and `0` disables eviction. Sibling and orphan `<name>.tar` archives
count toward the cap.
- **Images in use are pinned through `ImageManager`.** `pull_image(...,
instance_id=)` registers the sandbox as a user of the image while
holding the image's lock, and `release_image(image, instance_id)` drops
the pin. Eviction re-checks users under the same lock, so a pull can
never race an eviction, and mid-pull images (no `.extracted` marker) and
images whose lock is held are skipped. The gVisor backend pins on pull,
releases on every creation-failure path, and releases after teardown in
`delete_sandbox`, once the overlay's lower layer is unused. Backends
built on `BaseImageManager` get this for free.
- **The uncompressed tarball is gone.** Its only reader was a restore
branch that re-extracted it when the extracted directory had
disappeared, which nothing exercised, and it doubled every image's disk
footprint. Archives left by earlier versions count toward the cap and
are evicted with their image.

`RAY_SANDBOX_IMAGE_CACHE_MAX_BYTES` is documented in the sandboxes guide
under "Container images" and in the troubleshooting section.

## Related issue number

Follow-up to ray-project#65570; sibling of ray-project#65737 / ray-project#65744 / ray-project#65745 (the
Terminal-Bench fix series).

## Checks

- [x] Signed off (DCO); `ruff`, `black`, and `pydoclint` pass with the
pre-commit versions and flags.
- [x] Unit tests run without gVisor: `test_image_cache_eviction` (LRU
order, in-use and kept images protected, unextracted skipped, orphan
tarballs counted), `test_pull_pins_image_until_release` (pin on pull and
on cache hit, eviction blocked until release),
`test_image_cache_max_bytes_default_and_env`. The gVisor-gated
remote-pull test asserts no archive is written.

---------

Signed-off-by: xyuzh <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Co-authored-by: Philipp Moritz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants