bash - 带有集群配置的 Couchbase docker 入口点
问题描述
我正在寻找一种在 docker 中启动 couchbase (6.0.3) 的方法,然后在它准备好后,运行一个已知良好的 couchbase-cli 命令(见下文)来设置集群,而无需我做更多的事情比运行容器。
couchbase-cli cluster-init --cluster "couchbase://127.0.0.1" --cluster-name "couchbase" --cluster-username "admin" --cluster-password "password" --services "data,index,query" --cluster-ramsize 500 --cluster-index-ramsize 256 --index-storage-setting "memopt";
到目前为止,我尝试使用 docker-compose 的command
关键字来解决这个问题,如下所示
version: '2.4'
services:
couchbase:
image: couchbase:6.0.3
container_name: "couchbase"
restart: always
ports:
- 8091-8094:8091-8094
- 11210:11210
command: >
/bin/bash -c "
until curl -I -s http://localhost:8091/ui/index.html
do
echo 'Waiting for Couchbase to start (retrying in 3 seconds)...'
sleep 3
done
couchbase-cli cluster-init --cluster "couchbase://127.0.0.1" --cluster-name "couchbase" --cluster-username "admin" --cluster-password "password" --services "data,index,query" --cluster-ramsize 500 --cluster-index-ramsize 256 --index-storage-setting "memopt"
"
这导致了一个看似无休止的打印循环,Waiting for Couchbase to start (retrying in 3 seconds)...
在 localhost:8091 上无法访问 couchbase。
然后我改变了策略,决定基于 couchbase 映像创建自己的 Dockerfile,更改入口点以合并 couchbase-cli 命令,如下所示
Dockerfile:
FROM couchbase:6.0.3
RUN mkdir files
COPY initcouchbase.sh files/
RUN chmod +x files/initcouchbase.sh
ENTRYPOINT ./files/initcouchbase.sh
initcouchbase.sh
#!/usr/bin/env bash
/entrypoint.sh couchbase-server &
until curl -I -s http://localhost:8091/ui/index.html
do
echo 'Waiting for Couchbase to start (retrying in 3 seconds)...'
sleep 3
done
couchbase-cli cluster-init --cluster "couchbase://127.0.0.1" --cluster-name "couchbase" --cluster-username "admin" --cluster-password "password" --services "data,index,query" --cluster-ramsize 500 --cluster-index-ramsize 256 --index-storage-setting "memopt"
这种工作方式是,当 docker 日志显示集群已经配置了 cli-command 成功消息 ( SUCCESS: Cluster initialized
) 片刻后,就可以登录到本地集群了。然而,片刻之后,某些东西决定再次运行(我假设整个initcouchbase.sh
运行一遍又一遍),这使得 couchbase 在几秒钟内再次不可用,直到每次循环完成。
有没有人也尝试过并征服了它?除了下面链接的内容外,我在此处看不到有关此特定用例的太多内容,但答案并未涵盖我的问题的要点。
解决方案
推荐阅读
- amazon-web-services - 如何在 Databricks 中从一个 s3 帐户读取并写入另一个帐户
- python - 当单词中有重复字母时,如何制作正式文本?
- python - PyQt5 可执行文件在 py2app (macOS) 上不起作用
- firebase - 有没有办法将flutter_tts文件保存到firebase存储?
- c# - 我想在循环中显示列表项的索引
- c# - 表单设计器在打开表单时显示空白选项卡
- numpy - 列表的numpy数组到二维数组
- r - 基于R中的三个变量创建一个新变量
- webpack - mui-datatable 服务器端渲染“WebpackError:ReferenceError:未定义窗口”
- python - 如何将多个图像发送到烧瓶服务器?