我正在尝试使用 TestContainers 来运行 JUnit 测试。
但是,我得到了InternalServerErrorException: Status 500: {"message":"Get https://registry-1.docker.io/v2/: Forbidden"}
error.
请注意,我使用的是安全网络。
我可以通过这样做来复制这个docker pull testcontainers/ryuk
在命令行上。
$ docker pull testcontainers/ryuk
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: Forbidden
但是,我需要它从我们的 Nexus 服务中提取:https://nexus.company.com/18443
。
在 docker-compose 文件内,我已经使用了正确的 Nexus 图像路径。 (通过使用 docker-compose 手动启动来验证。但是 TestContainers 还会拉入 docker-compose 文件之外的其他映像。正是这些映像导致了失败。
我很高兴 Docker Desktop 或 TestContainers 配置更改可以为我解决这个问题。
注意:我已经尝试将 Nexus 的主机 URL 添加到仪表板上的 Docker 引擎 JSON 配置,执行时不会更改生成的错误docker pull
.
自从版本1.15.1
测试容器允许自动将前缀附加到所有 docker 镜像。如果您的私有注册表配置为 docker hub 镜像,此功能应该有助于解决上述问题。
引用自文档 https://www.testcontainers.org/features/image_name_substitution/#automatically-modifying-docker-hub-image-names:
然后,您可以配置 Testcontainers 将前缀registry.mycompany.com/mirror/应用于它尝试从 Docker Hub 提取的每个映像。这可以通过以下两种方式之一完成:
- 设置环境变量 TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=registry.mycompany.com/mirror/
- Via config file, setting hub.image.name.prefix in either:
- 用户主目录中的 ~/.testcontainers.properties 文件,或者
- 类路径上名为 testcontainers.properties 的文件
基本上设置与 docker-compose 文件中的图像相同的前缀。
如果由于某种原因您坚持使用旧版本,不推荐使用的解决方案是仅覆盖ryuk.container.image
财产。阅读相关内容here https://www.testcontainers.org/features/configuration/#customizing-images.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)