Docker Container is not adding N1QL support shows Bad request

n1ql

#1

I’m trying to Build docker container with support for Indexes and N1QL but the command

curl -u $CB_USER:$CB_PASS -v -X POST http://127.0.0.1:8091/node/controller/setupServices -d 'services=kv%2Cn1ql%2Cindex'

isn’t adding support for the same. I am using docker-compose and dockerfile is running this bash command

I have docker file command as

printf "Set hostname for cluster\n"
    curl -v -X POST -u $CB_USER:$CB_PASS \
      http://127.0.0.1:8091/node/controller/rename -d hostname=$CB_HOSTNAME

    printf "Setup Services for n1ql\n"
    curl -u $CB_USER:$CB_PASS -v -X POST http://127.0.0.1:8091/node/controller/setupServices -d 'services=kv%2Cn1ql%2Cindex'

The above command runs fine and update the hostname but when it comes to enable n1ql it shows 400 bad request.

here’re my Docker File contents

#!/usr/bin/env bash

cd / && ./entrypoint.sh couchbase-server &

httpstatus="000"

printf "Waiting for server to start\n"
while [ $httpstatus -ne "301" ]; do
  httpstatus=$(curl -s -o /dev/null -I -w "%{http_code}" http://127.0.0.1:8091/)
done

bucketstatus=$(curl -s -o /dev/null -I -w "%{http_code}" http://127.0.0.1:8091/pools/default/buckets/$BUCKET)

if [ $bucketstatus != 200 ]
  then
    printf "Set hostname for cluster\n"
    curl -v -X POST -u $CB_USER:$CB_PASS \
      http://127.0.0.1:8091/node/controller/rename -d hostname=$CB_HOSTNAME

    printf "Setup Services for n1ql\n"
    curl -u $CB_USER:$CB_PASS -v -X POST http://127.0.0.1:8091/node/controller/setupServices -d 'services=kv%2Cn1ql%2Cindex'

    printf "Setup admin\n"
    curl -s -X POST http://127.0.0.1:8091/settings/web \
      -d port=8091 \
      -d username=$CB_USER \
      -d password=$CB_PASS

    printf "\nCreating bucket\n"
    curl -s -X POST -u $CB_USER:$CB_PASS \
      -d name=$BUCKET \
      -d ramQuotaMB=300 \
      -d authType=sasl \
      http://127.0.0.1:8091/pools/default/buckets
fi

printf "Server ready\n"


while true; do sleep 1000; done

Followings are the logs

db_1          | Set hostname for cluster
db_1          | Note: Unnecessary use of -X or --request, POST is already inferred.
db_1          | *   Trying 127.0.0.1...
db_1          |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
db_1          |                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0)
db_1          | * Server auth using Basic with user 'admin'
db_1          | > POST /node/controller/rename HTTP/1.1
db_1          | > Host: 127.0.0.1:8091
db_1          | > Authorization: Basic YWRtaW46cGFzc3dvcmQ=
db_1          | > User-Agent: curl/7.49.1-DEV
db_1          | > Accept: */*
db_1          | > Content-Length: 18
db_1          | > Content-Type: application/x-www-form-urlencoded
db_1          | > 
db_1          | } [18 bytes data]
db_1          | * upload completely sent off: 18 out of 18 bytes
db_1          | < HTTP/1.1 200 OK
db_1          | < X-XSS-Protection: 1; mode=block
db_1          | < X-Permitted-Cross-Domain-Policies: none
db_1          | < X-Frame-Options: DENY
db_1          | < X-Content-Type-Options: nosniff
db_1          | < Server: Couchbase Server
db_1          | < Pragma: no-cache
db_1          | < Expires: Thu, 01 Jan 1970 00:00:00 GMT
db_1          | < Date: Tue, 06 Nov 2018 16:17:29 GMT
db_1          | < Content-Length: 0
db_1          | < Cache-Control: no-cache,no-store,must-revalidate
db_1          | < 
100    18    0     0  100    18      0    449 --:--:-- --:--:-- --:--:--   461
db_1          | * Connection #0 to host 127.0.0.1 left intact
db_1          | Setup Services for n1ql
db_1          | Note: Unnecessary use of -X or --request, POST is already inferred.
db_1          | *   Trying 127.0.0.1...
db_1          |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
db_1          |                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0)
db_1          | * Server auth using Basic with user 'admin'
db_1          | > POST /node/controller/setupServices HTTP/1.1
db_1          | > Host: 127.0.0.1:8091
db_1          | > Authorization: Basic YWRtaW46cGFzc3dvcmQ=
db_1          | > User-Agent: curl/7.49.1-DEV
db_1          | > Accept: */*
db_1          | > Content-Length: 26
db_1          | > Content-Type: application/x-www-form-urlencoded
db_1          | > 
db_1          | } [26 bytes data]
db_1          | * upload completely sent off: 26 out of 26 bytes
db_1          | < HTTP/1.1 400 Bad Request
db_1          | < X-XSS-Protection: 1; mode=block
db_1          | < X-Permitted-Cross-Domain-Policies: none
db_1          | < X-Frame-Options: DENY
db_1          | < X-Content-Type-Options: nosniff
db_1          | < Server: Couchbase Server
db_1          | < Pragma: no-cache
db_1          | < Expires: Thu, 01 Jan 1970 00:00:00 GMT
db_1          | < Date: Tue, 06 Nov 2018 16:17:29 GMT
db_1          | < Content-Type: application/json
db_1          | < Content-Length: 138
db_1          | < Cache-Control: no-cache,no-store,must-revalidate
db_1          | < 
db_1          | { [138 bytes data]
100   164  100   138  100    26  18020   3395 --:--:-- --:--:-- --:--:-- 19714
db_1          | * Connection #0 to host 127.0.0.1 left intact
db_1          | ["insufficient memory to satisfy memory quota for the services (requested quota is 1710MB, maximum allowed quota for the node is 1598MB)"]Setup admin
db_1          | {"newBaseUri":"http://127.0.0.1:8091/"}
db_1          | Creating bucket
db_1          | Server ready

Any help on this will be appriciated


#2

Hi @wpconsulate,

The rest call returns 400 with this message: [“insufficient memory to satisfy memory quota for the services (requested quota is 1710MB, maximum allowed quota for the node is 1598MB)”] . It looks like the Couchbase node is already initialized with some services taking up some amount of memory. When your rest call is sent, it is trying to add an additional service to the node with some default memory quota, but the requested memory is greater than total memory of the Couchbase node. Is the Couchbase node already initialized when you run this docker container? To get around this you can increase memory of Couchbase node. Also, a different solution would be to switch the order of “Setup hostname for cluster” and “Setup Services for n1ql” sections. Im not totally sure that will work but worth a try. Here is the documentation for using these rest calls to setup a cluster: https://docs.couchbase.com/server/5.5/rest-api/rest-node-provisioning.html. I will double check in the office if setting non-default memory quotas for services in the rest call is allowed.

–Korry


#3

I already tried changing the command sequence but no result. About the increase in RAM. I’m running this locally on Mac where docker container memory is set to 2GB but our dev server is Linux. So I updated the docker-compose file and added mem_limit: 3G

but still no result