1
votes

Running docker-machine version 0.5.0, Docker version 1.9.0 on OS X 10.11.1.

I've a Couchbase image of my own (not the official one). From inside the entrypoint script, I'm running some curl commands to configure the Couchbase server and to load sample data. Problem is, curl fails with error message Failed to connect to localhost port 8091: Connection refused. I've tried 127.0.0.1, 0.0.0.0, localhost, all without any success. netstat shows that port 8091 on localhost is listening. If I later log on to the server using docker exec and run the same curl commands, those work! What am I missing?

Error:

couchbase4 |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
couchbase4 |                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to localhost port 8091: Connection refused

netstat output:

root@cd4d3eb00666:/opt/couchbase/var/lib# netstat -lntu                              
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:21100           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:21101           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:9998          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:8091            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:8092            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:41125           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:11209           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:11210           0.0.0.0:*               LISTEN     
tcp6       0      0 :::11209                :::*                    LISTEN     
tcp6       0      0 :::11210                :::*                    LISTEN
2
Could you please post your entrypoint script? - Rene M.
@ReneM. Already there. The text 'entrypoint script' is a hyperlink. - Abhijit Sarkar
Wait a second! Your entrypoint script should start couchdb, So when your curl command failes in there but later works. I think you should think about the order of your commands in the entrypoint script. First start couchdb before you try to connect to it with curl ;) - Rene M.
@ReneM. You missed the very 1st line of the script? $CB_HOME/etc/couchbase_init.d restart - Abhijit Sarkar
You are running full linux with initd and stuff like that in your container? Why? Look up the official images, only run what needed, run your services by hand over your entrypoint script. Thats my advice - Rene M.

2 Answers

1
votes

Here is my Dockerfile:

FROM couchbase

COPY configure-cluster.sh /opt/couchbase

CMD ["/opt/couchbase/configure-cluster.sh"]

and configure-cluster.sh

/entrypoint.sh couchbase-server &

sleep 10

curl -v -X POST http://127.0.0.1:8091/pools/default -d memoryQuota=300 -d indexMemoryQuota=300
curl -v http://127.0.0.1:8091/node/controller/setupServices -d services=kv%2Cn1ql%2Cindex
curl -v http://127.0.0.1:8091/settings/web -d port=8091 -d username=Administrator -d password=password
curl -v -u Administrator:password -X POST http://127.0.0.1:8091/sampleBuckets/install -d '["travel-sample"]'

This configures the Couchbase server but still debugging how to bring Couchbase back in foreground.

Complete details at: https://github.com/arun-gupta/docker-images/tree/master/couchbase

0
votes

It turns out that if I do the curls after restarting the server, those work. Go figure! That said, note that the REST API for installing sample buckets is undocumented as far as I know. arun-gupta's blog and his answer here are the only places where I saw any mention of a REST call for installing sample buckets. There's a python script available but that requires installing python-httplib2.

That said, arun-gupta's last curl statement may be improved upon as follows:

if [ -n "$SAMPLE_BUCKETS" ]; then
    IFS=',' read -ra BUCKETS <<< "$SAMPLE_BUCKETS"

    for bucket in "${BUCKETS[@]}"; do
        printf "\n[INFO] Installing %s.\n" "$bucket"
        curl -sSL -w "%{http_code} %{url_effective}\\n" -u $CB_USERNAME:$CB_PASSWORD --data-ascii '["'"$bucket"'"]' $ENDPOINT/sampleBuckets/install
    done
fi

where SAMPLE_BUCKETS can be a comma-separated environment variable, possible values being combinations of gamesim-sample, beer-sample and travel-sample. The --data-ascii option keeps curl from choking on the dynamically created JSON.

Now if only there was an easy way to start the server in the foreground. :)