带有集群配置的 Couchbase docker 入口点

问题描述 投票:0回答:1

我正在寻找一种在 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 命令成功消息 (

SUCCESS: Cluster initialized
) 一段时间后,就可以登录到本地集群了。然而,过了一会儿,有些东西决定再次运行(我假设整个
initcouchbase.sh
一遍又一遍地运行),这使得 couchbase 再次不可用几秒钟,直到每次循环完成。

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

docker 上的 couchbase 配置

bash docker couchbase
1个回答
0
投票

您将

initcouchbase.sh
定义为入口点。因此,将启动 bash,执行此脚本。一旦脚本终止,bash 就会终止,并且 Docker 不会看到容器正在运行。根据 Docker 运行容器的配置方式,它可能会直接尝试再次启动它。

参见 https://docs.docker.com/engine/containers/start-containers-automatically/

因此,您需要更改脚本才能保持忙碌。或者恢复后台进程(Couchbase)以再次在前台运行。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.