docker 容器的自动化服务 (couchbase) 配置

Automate service (couchbase) configuration of a docker container

我想我在这里遗漏了一些 Docker 概念。

我想在 couchbase 中进行一些初始配置:

我在 Docker 文件中添加了 couchbase-cli 命令,但是当在 CMD 之后执行 运行 指令时,couchbase 服务在构建时不可用。

自动配置 couchbase 服务的最佳方法是什么?

这是完整的 Docker 文件。

FROM ubuntu:12.04

MAINTAINER Couchbase Docker Team <docker@couchbase.com>

# Install dependencies
RUN apt-get update && \
    apt-get install -yq runit wget python-httplib2  && \
    apt-get autoremove && apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV CB_VERSION=4.1.0 \
    CB_RELEASE_URL=http://packages.couchbase.com/releases \
    CB_PACKAGE=couchbase-server-enterprise_4.1.0-ubuntu12.04_amd64.deb \
    CB_SHA256=38b92711a52cbb0f8d4ab977e0ea2fb4e25022a0660dacc26fd7a60031eb70d2 \
    PATH=$PATH:/opt/couchbase/bin:/opt/couchbase/bin/tools:/opt/couchbase/bin/install \
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/couchbase/lib

# Create Couchbase user with UID 1000 (necessary to match default
# boot2docker UID)
RUN groupadd -g 1000 couchbase && useradd couchbase -u 1000 -g couchbase -M

# Install couchbase
RUN wget -N $CB_RELEASE_URL/$CB_VERSION/$CB_PACKAGE && \
    echo "$CB_SHA256  $CB_PACKAGE" | sha256sum -c - && \
    dpkg -i ./$CB_PACKAGE && rm -f ./$CB_PACKAGE

# Add runit script for couchbase-server
COPY scripts/run /etc/service/couchbase-server/run

# Add bootstrap script
COPY scripts/entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD ["couchbase-server"]

RUN couchbase-cli cluster-init -c localhost:8091 \
    --cluster-username=admin --cluster-password=test --cluster-init-ramsize=600  \
    -u Administrator -p password

RUN couchbase-cli bucket-create -c localhost:8091 -u admin -p test  --bucket=web-chat \
      --bucket-type=couchbase  \
      --bucket-port=11222  \
      --bucket-ramsize=500  \
      --bucket-replica=1

EXPOSE 8091 8092 8093 11207 11210 11211 18091 18092
VOLUME /opt/couchbase/var

当我尝试 运行 couchbase-cli 时发生错误,因为 couchbase 服务在构建时不可用:

 Step 12 : RUN couchbase-cli cluster-init -c localhost:8091     --cluster-username=admin --cluster-password=mtd123 --cluster-init-ramsize=600      -u Administrator -p password
 ---> Running in 0cd5228e8443
ERROR: command: cluster-init: localhost:8091, [Errno 111] Connection refused
ERROR: Service 'couchbase' failed to build: The command '/bin/sh -c couchbase-cli cluster-init -c localhost:8091     --cluster-username=admin --cluster-password=mtd123 --cluster-init-ramsize=600      -u Administrator -p password' returned a non-zero code: 1

发生此错误是因为 Couchbase 未 运行ning。您可以 运行 在与安装它相同的 运行 步骤中完成这些操作。

RUN wget -N $CB_RELEASE_URL/$CB_VERSION/$CB_PACKAGE && \
    echo "$CB_SHA256  $CB_PACKAGE" | sha256sum -c - && \
    dpkg -i ./$CB_PACKAGE && rm -f ./$CB_PACKAGE && \
    couchbase-cli cluster-init -c localhost:8091 \
    --cluster-username=admin --cluster-password=test --cluster-init-ramsize=600  \
    -u Administrator -p password