我正在使用docker.elastic.co/elasticsearch/elasticsearch-oss:7.3.2
使用testcontainers.org,我想用它来测试我要更新的插件,但是我找不到在测试环境中安装它的方法。
我可以尝试在其中复制文件并安装
ElasticsearchContainer container = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch-oss:$ELASTIC_VERSION")
String pluginPath = "/usr/share/elasticsearch/$PLUGIN_FILE_NAME"
container.start()
container.copyFileToContainer(MountableFile.forHostPath(new File(PLUGIN_PLUGIN_PATH).toPath()), pluginPath)
ExecResult result = container.execInContainer("bin/elasticsearch-plugin", "install", "file://$pluginPath")
但是随后容器已经启动并且弹性搜索已经在运行,因此将不会加载插件,因此我需要杀死它并复制它的创建方式,听起来像是在窃听。有更好的方法吗?
答案 0 :(得分:1)
我通过使用order_by
例如,以下代码段对我有用:
@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);