如何通过-D参数或Maven属性配置Testcontainers的ryuk.container.image
解决方案
一、通过命令行-D参数正确指定Ryuk镜像
Testcontainers的系统属性需以testcontainers.作为前缀,你之前尝试的参数不符合正确命名规则。正确的命令行参数格式为:
-Dtestcontainers.ryuk.container.image=你的私有仓库地址/ryuk:镜像标签
如果是通过环境变量配置,才使用全大写加下划线的格式:
TESTCONTAINERS_RYUK_CONTAINER_IMAGE=你的私有仓库地址/ryuk:镜像标签
二、用Maven属性替换testcontainers.properties中的配置
要让Maven自动替换配置文件里的${my.property},需开启资源过滤功能:
- 将
testcontainers.properties放置在src/test/resources目录下(测试场景的配置建议放这里) - 在
pom.xml中添加资源过滤配置,指定对该文件开启变量替换:
<build> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <includes> <include>testcontainers.properties</include> </includes> </testResource> </testResources> </build>
- 在
pom.xml中定义你的Maven属性:
<properties> <my.property>你的私有仓库地址/ryuk:镜像标签</my.property> </properties>
- 在
testcontainers.properties中引用该属性:
ryuk.container.image=${my.property}
执行Maven构建时,Maven会自动完成${my.property}的变量替换。
内容的提问来源于stack exchange,提问作者Max
相关产品推荐
相关产品推荐

