使用cassandra在docker容器内自动创建密钥空间 [英] Create keyspace automatically inside docker container with cassandra
问题描述
我想知道是否有人尝试使用默认键空间构建cassandra docker映像,但我尝试在BUILD时间内完成该操作,但由于cassandra不在该阶段运行,因此无法正常工作。类似于以下内容:
I was wondering if someone has tried to build a cassandra docker image with default keyspace, I've tried to do it on BUILD time but it doesn't work because cassandra is not running in that phase. It was something similar to this:
FROM cassandra:2.0
COPY ../somewhere/keyspace_definition.txt /src/keyspace_definition.txt
RUN /usr/bin/cqlsh -f /src/keyspace_definition.txt
<我的新方法将是从入口点脚本执行此操作,但是,如果其他人有更好的主意,我现在想。
My new approach will be to do it from the entrypoint script, but, I wanted to now if someone else has a better idea.
快乐运输:D
推荐答案
今天解决了此问题。构建映像,该映像将覆盖修改后的默认Cassandra docker-entrypoint.sh
,并在 exec $ @
Tackled this issue today. Build image, which overwrites default Cassandra docker-entrypoint.sh
with one modified, appended, right before exec "$@"
for f in docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.cql) echo "$0: running $f" && until cqlsh -f "$f"; do >&2 echo "Cassandra is unavailable - sleeping"; sleep 2; done & ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
输入所需的* .cql在 docker-entrypoint-initdb.d /
中的图像中。
Put the desired *.cql in image in docker-entrypoint-initdb.d/
.
图像将启动,启动cassandra,然后除非成功,否则将重试插入数据库。只要确保您的脚本是如果不存在
,否则脚本将无限期运行。
Image will start, boot up the cassandra, and retries inserting to the database unless it succeeds. Just make sure your scripts are IF NOT EXISTS
otherwise the script will run indefinitely.
这篇关于使用cassandra在docker容器内自动创建密钥空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!