首页 > 解决方案 > 带有集群配置的 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 在几秒钟内再次不可用,直到每次循环完成。

有没有人也尝试过并征服了它?除了下面链接的内容外,我在此处看不到有关此特定用例的太多内容,但答案并未涵盖我的问题的要点。

docker 上的 couchbase 配置

标签: bashdockercouchbase

解决方案


推荐阅读