如何配置 docker/docker-compose 默认使用 Nexus 而不是 docker.io?
How to configure docker/docker-compose to use Nexus by default instead of docker.io?
我正在尝试使用 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 桌面或 TestContainers 配置更改可以为我解决此问题。
注意:我已经尝试将 nexus 的主机 URL 添加到仪表板上的 Docker 引擎 JSON 配置,执行 docker pull
.
过程描述于this page:
将以下内容添加到您的 Docker 守护程序配置中:
{
"registry-mirrors": ["https://nexus.company.com:18443"]
}
确保重新启动守护程序以应用更改。
自版本 1.15.1
起,测试容器允许自动将前缀附加到所有 docker 图像。如果您的私有注册表配置为 docker 中心镜像,此功能应该有助于解决上述问题。
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。
我正在尝试使用 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 桌面或 TestContainers 配置更改可以为我解决此问题。
注意:我已经尝试将 nexus 的主机 URL 添加到仪表板上的 Docker 引擎 JSON 配置,执行 docker pull
.
过程描述于this page:
将以下内容添加到您的 Docker 守护程序配置中:
{
"registry-mirrors": ["https://nexus.company.com:18443"]
}
确保重新启动守护程序以应用更改。
自版本 1.15.1
起,测试容器允许自动将前缀附加到所有 docker 图像。如果您的私有注册表配置为 docker 中心镜像,此功能应该有助于解决上述问题。
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。