[Enhancement]: RemoteDockerImage silently falls back to linux/amd64 on any pull failure, leaving a wrong-architecture image on non-amd64 hosts

未关闭
#12,180 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
docker, java

调研方向

Start from RemoteDockerImage.pullImage in the core module, where the catch (DockerClientException | NotFoundException) block retries with withPlatform("linux/amd64"); read the surrounding tryImagePullCommand retry loop and #4290 to see why it exists. Pick the gate (daemon architecture, or a new testcontainers.properties key), then add a WARN with image name, original message, host arch and retried platform. Done means the fallback no longer fires on quota, auth or network errors or on non-arm64 hosts, with a test covering both paths.

由索引模型根据 Issue 内容生成。

描述

Module

Core

Proposal

RemoteDockerImage.pullImage(...) retries a failed pull with withPlatform("linux/amd64") for any DockerClientException or NotFoundException, on any host architecture, and logs nothing when it does. On ppc64le or s390x hosts this can leave an amd64 image under the regular tag. The default pull policy then reuses that image forever, and containers fail with exec format error.

Current behavior

Code in 2.0.5 (the fallback was introduced in 1.16.0 by #4290, "Fallback to x86 image if image pulling fails"):

private TimeLimitedLoggedPullImageResultCallback pullImage(PullImageCmd pullImageCmd, Logger logger)
    throws InterruptedException {
    try {
        return pullImageCmd.exec(new TimeLimitedLoggedPullImageResultCallback(logger)).awaitCompletion();
    } catch (DockerClientException | NotFoundException e) {
        // Try to fallback to x86
        return pullImageCmd
            .withPlatform("linux/amd64")
            .exec(new TimeLimitedLoggedPullImageResultCallback(logger))
            .awaitCompletion();
    }
}

Problems:

  1. It isn't limited to hosts where it makes sense. The intent, from the comment and the PR title, is Apple Silicon/arm64 hosts pulling x86-only images, where amd64 images run under emulation. On ppc64le or s390x there is generally no amd64 emulation, so the pulled image is unusable.
  2. The exceptions are too broad. DockerClientException is also what docker-java's PullImageResultCallback throws for any failed pull, for example Could not pull image: toomanyrequests: Quota exceeded .... That is a registry or mirror quota error, unrelated to a missing platform, yet it triggers the amd64 retry.
  3. The fallback is silent. The catch block logs nothing, so the original error and the platform switch are invisible, even at DEBUG. The only visible trace is the later exec format error.
  4. The wrong image sticks. The amd64 image is stored under the normal tag, and the default pull policy only pulls images that aren't available locally. Every later run reuses the bad image until it is removed manually. Pulling with the Docker CLI works, because it is pinned to the host platform and fails loudly.
Real-world impact

Apache Camel CI (CAMEL-26387) has ppc64le and s390x Jenkins nodes behind a registry mirror (mirror.gcr.io). The mirror intermittently returns:

toomanyrequests: Quota exceeded for quota metric 'Read requests to external upstream hosts per organization per host ...'

This mostly affects ppc64le and s390x, probably because amd64 content is usually already cached by the mirror, so the amd64 retry succeeds. Images such as postgres, redis, nats, solr, cassandra and rabbitmq ended up as amd64 on ppc64le and s390x nodes and then failed with exec format error.

Proposed improvements

Any combination of the following would help:

  1. Restrict the fallback by host architecture. Only fall back to linux/amd64 when the Docker daemon's architecture is arm64/aarch64. Alternatively, make it configurable, for example a pull.platform.fallback property in testcontainers.properties or an environment variable, taking linux/amd64, none, or auto (the default).
  2. Be more selective on the error. Fall back only when the failure indicates a missing platform in the manifest, for example no matching manifest for linux/ppc64le in the manifest list entries. Do not fall back on quota errors (toomanyrequests), auth errors, network errors or InternalServerErrorException. Those should keep using the existing retry loop in tryImagePullCommand.
  3. Log the fallback. At WARN, include the image name, the original exception message, the host architecture and the platform used for the retry. For example: Pulling image X failed (<message>); retrying for platform linux/amd64. This image may not run on this host (<arch>).
  4. Optionally, verify after the fallback. If the pulled image architecture differs from the daemon's and no emulation is expected, log a warning, or fail fast with a clear message.
Workaround
  • Pre-pull on the node with docker pull --platform linux/<arch> <image> before the tests, so Testcontainers finds the image locally.
  • Use a custom ImagePullPolicy registered with pull.policy=<fully qualified class name> in a testcontainers.properties file on the classpath. Apache Camel uses HostArchitectureImagePullPolicy in https://github.com/apache/camel/pull/30672. If the local image architecture differs from the host's, it logs a warning, removes the image and pulls it again. If the image is missing, it pulls it itself with withPlatform("linux/<host arch>"), so the linux/amd64 fallback never runs. It then checks the architecture again and throws ContainerFetchException on a failure or mismatch.
Environment
  • Testcontainers 2.0.5 (the code is unchanged since 1.16.0 in the versions I looked at)
  • docker-java 3.7.1
  • Hosts: Linux ppc64le and s390x, with Docker or Podman

This issue was drafted by IBM Bob (AI assistant) on behalf of @apupier.

主要语言
Java
星标
8.8k
派生
2k
平均合并
2 天 1 小时
30 天内合并 PR
11

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

testcontainers/testcontainers-java 的其他 Issue

查看 testcontainers/testcontainers-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。