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條經驗 獲得超13個贊
我能夠通過這種方式啟動帶有插件的 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()
}
添加回答
舉報