3 回答
TA贡献1851条经验 获得超3个赞
例如,以下代码片段对我有用:
@ClassRule
public static GenericContainer elastic = new GenericContainer(new ImageFromDockerfile()
.withDockerfileFromBuilder(
builder -> builder.from("elasticsearch:6.8.4")
.run("bin/elasticsearch-plugin", "install", "analysis-icu")
.run("bin/elasticsearch-plugin", "install", "analysis-smartcn")
.build()
)).withExposedPorts(9200);
TA贡献1860条经验 获得超9个赞
对我来说这有效:
private static final String DOCKER_IMAGE = "docker.elastic.co/elasticsearch/elasticsearch:6.8.5"
private static final ElasticsearchContainer container = new ElasticsearchContainer(DOCKER_IMAGE);
static {
container.withCreateContainerCmdModifier((cmd) -> {
cmd.withCmd(
"bash", "-c", "./bin/elasticsearch-plugin install analysis-icu && docker-entrypoint.sh eswrapper");
});
container.withStartupTimeout(Duration.ofSeconds(60));
}
@BeforeClass
public static void start() {
container.start();
}
@AfterClass
public static void stop() {
container.stop();
}
请注意,本示例中的 Elasticsearch 版本 6.8.5 较旧,您可能应该使用较新的版本。
TA贡献1842条经验 获得超12个赞
我能够通过这种方式启动带有插件的 Elasticsearch 测试容器(这是 Kotlin 代码):
ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:7.10.0").apply {
withCreateContainerCmdModifier { cmd ->
cmd.withCmd(
*arrayOf(
"bash",
"-c",
"""/usr/share/elasticsearch/bin/elasticsearch-plugin install <URL> &&
su elasticsearch -s /usr/share/elasticsearch/bin/elasticsearch
""".trimIndent()
)
)
}
start()
}
添加回答
举报