gpt4 book ai didi

docker - 如何配置 docker/docker-compose 默认使用 Nexus 而不是 docker.io?

转载 作者:行者123 更新时间:2023-12-02 16:21:02 25 4
gpt4 key购买 nike

我正在尝试使用 TestContainers 来运行 JUnit 测试。但是,我收到了 InternalServerErrorException: Status 500: {"message":"Get https://registry-1.docker.io/v2/: Forbidden"} 错误。

请注意,我使用的是安全网络。

我可以通过在命令行上执行 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 图像。如果您的私有(private)注册表配置为 docker hub 镜像,此功能应该有助于解决上述问题。

引自documentation :

You can then configure Testcontainers to apply the prefix registry.mycompany.com/mirror/ to every image that it tries to pull from Docker Hub. This can be done in one of two ways:

  • Setting environment variables TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=registry.mycompany.com/mirror/
  • Via config file, setting hub.image.name.prefix in either:
    • the ~/.testcontainers.properties file in your user home directory, or
    • a file named testcontainers.properties on the classpath

基本上设置与 docker-compose 文件中的图像相同的前缀。

如果您出于某种原因坚持使用旧版本,一个不推荐的解决方案是仅覆盖 ryuk.container.image 属性。了解一下 here .

关于docker - 如何配置 docker/docker-compose 默认使用 Nexus 而不是 docker.io?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65510651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com