我的Docker文件。
我想在容器内提取Cassandra镜像并创建超级用户时运行类似的操作。
FROM cassandra:4.0
MAINTAINER me
EXPOSE 9042
我想在容器内提取Cassandra镜像并创建超级用户时运行类似的操作。
create keyspace IF NOT EXISTS XYZ WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
我还尝试过添加一个shell脚本,但它从未连接到cassandra,我的修改后的docker文件如下:
FROM cassandra:4.0
MAINTAINER me
ADD entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod 755 /usr/local/bin/entrypoint.sh
RUN mkdir scripts
COPY alter.cql scripts/
RUN chmod 755 scripts/alter.cql
EXPOSE 9042
CMD ["entrypoint.sh"]
我的入口点看起来像这样
#!/bin/bash
export CQLVERSION=${CQLVERSION:-"4.0"}
export CQLSH_HOST=${CQLSH_HOST:-"localhost"}
export CQLSH_PORT=${CQLSH_PORT:-"9042"}
cqlsh=( cqlsh --cqlversion ${CQLVERSION} )
# test connection to cassandra
echo "Checking connection to cassandra..."
for i in {1..30}; do
if "${cqlsh[@]}" -e "show host;" 2> /dev/null; then
break
fi
echo "Can't establish connection, will retry again in $i seconds"
sleep $i
done
if [ "$i" = 30 ]; then
echo >&2 "Failed to connect to cassandra at ${CQLSH_HOST}:${CQLSH_PORT}"
exit 1
fi
# iterate over the cql files in /scripts folder and execute each one
for file in /scripts/*.cql; do
[ -e "$file" ] || continue
echo "Executing $file..."
"${cqlsh[@]}" -f "$file"
done
echo "Done."
exit 0
我的代码一直连接不上Cassandra数据库,有什么建议吗?谢谢。
Checking connection to cassandra... Can't establish connection, will retry again in 1 seconds Can't establish connection, will retry again in 2 seconds Can't establish connection, will retry again in 3 second
,最终终止输出。 - Ankush Virmani