I created docker-compose file for couchbase cluster.
But N1QL don’t work.
HELP ME !!
couchbase docker version: couchbase:community
/Applications/Couchbase\ Server.app/Contents/Resources/couchbase-core/bin/cbq -engine=http://localhost:8091/
Couchbase query shell connected to http://localhost:8091/ . Type Ctrl-D to exit.
cbq> SELECT DISTINCT type FROM `beer-sample`;
Requested resource not found.
/Applications/Couchbase\ Server.app/Contents/Resources/couchbase-core/bin/cbq -engine=http://localhost:8093/
Couchbase query shell connected to http://localhost:8093/ . Type Ctrl-D to exit.
cbq> SELECT DISTINCT type FROM `beer-sample`;
ERROR 5000 : Post http://localhost:8093/query: EOF
docker-compose.yml
services:
couchbase1:
container_name: couchbase1
extends:
file: common.yml
service: couchbase
volumes:
- ./export/var/couchbase/node1:/opt/couchbase/var
ports:
- 8091:8091
- 8092:8092
- 8093:8093
- 8094:8094
- 11210:11210
couchbase2:
container_name: couchbase2
extends:
file: common.yml
service: couchbase
volumes:
- ./export/var/couchbase/node2:/opt/couchbase/var
couchbase3:
container_name: couchbase3
extends:
file: common.yml
service: couchbase
volumes:
- ./export/var/couchbase/node3:/opt/couchbase/var
intializer:
container_name: cbclusterinit
depends_on:
- couchbase1
- couchbase2
- couchbase3
environment:
COUCHBASE_HOSTS: "couchbase1,couchbase2,couchbase3"
COUCHBASE_PORT: 8091
COUCHBASE_BUCKET: mybucket
build: images/cbclusterinit
image: avcbinit:custom
shell in intializer
#!/bin/bash
# Initialize a couchbase cluster. The comma-separated list of hosts can be
# set in $COUCHBASE_HOSTS in the docker-compose.yml file.
echo hosts ${COUCHBASE_HOSTS}
: ${COUCHBASE_HOSTS:=couchbase1}
: ${COUCHBASE_PORT:=8091}
: ${COUCHBASE_BUCKET:=default}
: ${USER:=couchbase}
: ${PASSWORD:=couchbase}
: ${CLUSTER_RAMSIZE:=512}
: ${BUCKET_RAMSIZE:=100}
: ${BUCKET_REPLICAS:=1}
: ${BUCKET_TYPE:=couchbase}
IFS=', ' read -r -a array <<< "${COUCHBASE_HOSTS}"
first_node=${array[0]}
s=1
i=0
while ! nc -w 1 $first_node $COUCHBASE_PORT 2>/dev/null
do
i=$((i+1))
if [ $i -gt 5 ]; then
exit 1
fi
echo "Couchbase is not yet available at ${first_node}:${COUCHBASE_PORT}, sleeping $s seconds..."
sleep $s
s=$((s*2))
done
echo "Initializing Couchbase first node ${first_node}..."
/opt/couchbase/bin/couchbase-cli bucket-create \
-c ${first_node}:${COUCHBASE_PORT} \
-u ${USER} -p ${PASSWORD} \
--bucket=${COUCHBASE_BUCKET} \
--bucket-type=${BUCKET_TYPE} \
--bucket-ramsize=${BUCKET_RAMSIZE} \
--bucket-replica=${BUCKET_REPLICAS}
/opt/couchbase/bin/couchbase-cli cluster-init \
-c ${first_node}:${COUCHBASE_PORT} \
--cluster-init-username=${USER} --cluster-init-password=${PASSWORD} \
--cluster-init-port=${COUCHBASE_PORT} \
--cluster-init-ramsize=${CLUSTER_RAMSIZE}
# --services=data,index,query
/opt/couchbase/bin/couchbase-cli cluster-init \
-c ${first_node}:${COUCHBASE_PORT} \
-u ${USER} -p ${PASSWORD} \
--cluster-init-port=${COUCHBASE_PORT} \
--cluster-init-ramsize=${CLUSTER_RAMSIZE}
# --services=data,index,query
echo "Initializing couchbase cluster"
for h in "${array[@]:1}"
do
echo "Adding $h to cluster..."
IP=$(getent hosts ${h} | awk '{print $1}')
s=1
i=0
while ! nc -w 1 $h $COUCHBASE_PORT 2>/dev/null
do
i=$((i+1))
if [ $i -gt 5 ]; then
exit 2
fi
echo "Couchbase is not yet available at ${h}:${COUCHBASE_PORT}, sleeping $s seconds..."
sleep $s
s=$((s*2))
done
/opt/couchbase/bin/couchbase-cli server-add \
--cluster=${first_node}:${COUCHBASE_PORT} \
-u ${USER} -p ${PASSWORD} \
--server-add=${IP}:${COUCHBASE_PORT} \
--server-add-username=${USER} \
--server-add-password=${PASSWORD}
done
echo "Reblancing cluster"
/opt/couchbase/bin/couchbase-cli rebalance -c ${first_node}:${COUCHBASE_PORT} -u ${USER} -p ${PASSWORD}
# Disable runnability so we only run once...
chmod a-x /cbinit-entrypoint.sh
echo "Cluster ready"