如何将docker/docker-compose配置为默认使用Nexus而不是docker.io? [英] How to configure docker/docker-compose to use Nexus by default instead of docker.io?
问题描述
我正在尝试使用TestContainers运行JUnit测试.但是,我收到一个 InternalServerErrorException:状态500:{消息":获取https://registry-1.docker.io/v2/:禁止使用"}
错误.>>
请注意,我在安全的网络上.
我可以通过在命令行上执行 docker pull testcontainers/ryuk
来复制此代码.
$ docker pull testcontainers/ryuk使用默认标签:最新来自守护程序的错误响应:获取https://registry-1.docker.io/v2/:禁止
但是,我需要它从我们的nexus服务中提取: https://nexus.company.com/18443
.在docker-compose文件中,我已经在使用正确的nexus映像路径.(通过使用docker-compose手动启动进行验证.不过,TestContainers还会提取docker-compose文件之外的其他映像.正是这些映像导致了失败.
我很高兴能为我解决此问题的Docker桌面或TestContainers配置更改.
注意:我已经尝试过将仪表板的Docker的Nexus的主机URL添加到仪表板上的Docker Engine JSON配置中,而执行 docker pull
时所产生的错误没有任何改变.
由于版本 1.15.1
,测试容器允许将前缀自动添加到所有docker映像.如果您的私人注册表配置为docker hub镜像,则此功能应有助于解决上述问题.
文档的引用:
然后,您可以配置Testcontainers将前缀Registry.mycompany.com/mirror/应用于它尝试从Docker Hub提取的每个映像.可以通过以下两种方式之一完成此操作:
- 设置环境变量TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = registry.mycompany.com/mirror/
- 通过配置文件,在以下任一位置设置hub.image.name.prefix:
- 用户主目录中的〜/.testcontainers.properties文件,或
- 类路径上名为testcontainers.properties的文件
基本上为docker-compose文件中的图像设置相同的前缀.
如果由于某种原因而使用旧版本,不建议使用的解决方案是仅覆盖 ryuk.container.image
属性.在此处中进行阅读.
I'm trying to use TestContainers to run JUnit tests.
However, I'm getting a InternalServerErrorException: Status 500: {"message":"Get https://registry-1.docker.io/v2/: Forbidden"}
error.
Please note, that I am on a secure network.
I can replicate this by doing docker pull testcontainers/ryuk
on the command line.
$ docker pull testcontainers/ryuk
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: Forbidden
However, I need it to pull from our nexus service: https://nexus.company.com/18443
.
Inside the docker-compose file, I'm already using the correct nexus image path. (Verified by manually starting it with docker-compose. However TestContainers also pulls in additional images which are outside the docker-compose file. It is these images that are causing the failure.
I'd be glad for either a Docker Desktop or TestContainers configuration change that would fix this for me.
Note: I've already tried adding the host URL for nexus to the Docker Engine JSON configuration on the dashboard, with no change to the resulting error when doing docker pull
.
Since the version 1.15.1
Testcontainers allow to automatically append prefixes to all docker images. In case your private registry is configured as a docker hub mirror this functionality should help with the mentioned issue.
Quote from the 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
Basically set the same prefix you did for the images in your docker-compose file.
If you're stuck with older versions for some reason, a deprecated solution would be to override just the ryuk.container.image
property. Read about it here.
这篇关于如何将docker/docker-compose配置为默认使用Nexus而不是docker.io?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!