我将使用官方的Elasticsearch图片。我想要做的是在Docker运行期间设置索引的映射。
所以我需要在容器启动后立即执行。
curl -XPUT localhost:9200 / _template / http_request -d {.....}
所以我不能在Dockerfile中这样做,或者我可以吗?
谢谢
答案 0 :(得分:5)
我最终做了这个
搬运工-composer.yml
version: '2'
services:
elasticsearch:
image: elasticsearch:2.3
command: elasticsearch -Des.network.host=0.0.0.0
ports:
- "9200:9200"
- "9300:9300"
elasticsearch-mapping-init:
build: elasticsearch-mapping-init
links:
- elasticsearch
depends_on:
- elasticsearch
这是我的elasticsearch-mapping-init / Dockerfile:
FROM ubuntu
# Install packages
RUN apt-get update && \
apt-get install -y curl
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
这是我的elasticsearch-mapping-init / docker-entrypoint.sh
#!/bin/bash
for i in {30..0}; do
if curl elasticsearch:9200; then
curl -XPUT elasticsearch:9200/_template/log -d '
{
"template" : "log-*",
"settings": {
"number_of_shards": 1
},
"mappings" : {
}
}';
break;
fi
sleep 2
done
我认为这并不完美,我仍然在寻找更好的解决方案。