我认为我在这里缺少一些Docker概念。
我想在couchbase中进行一些初始配置:
我已经在Dockerfile中添加了couchbase-cli命令,但是当在CMD之后执行RUN指令时,在构建时就无法使用couchbase服务。
自动配置Couchbase服务的最佳方法是什么?
这是完整的Dockerfile。
FROM ubuntu:12.04
MAINTAINER Couchbase Docker Team <[email protected]>
# 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是该行时,就会发生错误,因为在构建时就无法使用ouchbase服务:
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未运行,因此发生此错误。您可以在安装它的同一运行步骤中运行它们。
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
关于docker - 自动化Docker容器的服务(couchbase)配置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35421608/