我想我在这里错过了一些Docker概念。
我想在couchbase中进行一些初始配置:
我在Dockerfile中添加了couchbase-cli命令,但是当在CMD之后执行RUN指令时,在构建时不能使用couchbase服务。
自动配置couchbase服务的最佳方法是什么?
这是完整的Dockerfile。
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
答案 0 :(得分:0)
发生此错误是因为Couchbase未运行。您可以在安装它的相同RUN步骤中运行它们。
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