Docker data volumes with couchbase

Hi Guys,

Recently I am facing a crazy problem, I have a docker image that runs Couchbase enterprise 3.0.2

It’s in a private repository currently. So lets just say the name of it is:

matt/couchbase

In order to allow the data to persist should matt/couchbase be removed I created a data only container based on matt/couchbase called matt/couchbase-data

The Dockerfile looks like

FROM matt/couchbase
CMD ["true"]
VOLUME ["/opt/couchbase/var/lib/couchbase/data"]

According to the couchbase docks, the volume path above is meant to be where couchbase stores it’s data.

So I run matt/couchbase-data, and then run matt/couchbase with a --volumes-from link.

That works fine. docker inspect couchbase shows:

"Volumes": {
        "/opt/couchbase/var/lib/couchbase/data": "/var/lib/docker/vfs/dir/f129a034a2b0474392fe98bdc37429f172be26c93a058540f3a1043d324c0b1c"
    },
    "VolumesRW": {
        "/opt/couchbase/var/lib/couchbase/data": true
    }

and docker inspect couchbase-data contains:

"Volumes": {
        "/opt/couchbase/var/lib/couchbase/data": "/var/lib/docker/vfs/dir/f129a034a2b0474392fe98bdc37429f172be26c93a058540f3a1043d324c0b1c"
    },
    "VolumesRW": {
        "/opt/couchbase/var/lib/couchbase/data": true
    }

So it would appear that the the two containers linked up just fine.

However, the problem is this. When I stop the container named “couchbase”, and remove it with docker rm, then start couchbase again, the data is gone despite docker-inspect indicating that the volume is still alive with the same real path as before. i.e. /var/lib/docker/vfs/dir/f129a034a2b0474392fe98bdc37429f172be26c93a058540f3a1043d324c0b1c

This might be relevant. The couchbase server is being started with the following init script which I obtained from another docker couchbase project (sorry, lost the link temporarily).

I thought perhaps cluster-init below (which is what I run by default for couchbase) might be resetting the data. But according to the docs it just sets the cluster username,password and port.

Any ideas?

#!/bin/bash
set +e

echo 'removing document size limit'
sed -i 's/return getStringBytes(json) > self.docBytesLimit;/return false/g' /opt/couchbase/lib/ns_server/erlang/lib/ns_server/priv/public/js/documents.js

echo 'starting couchbase'
/etc/init.d/couchbase-server restart

wait_for_start() {
    "$@"
    while [ $? -ne 0 ]
    do
        echo 'waiting for couchbase to start'
        sleep 1
        "$@"
    done
}


if [ -z "$CLUSTER_INIT_USER" ] || [ -z "$CLUSTER_INIT_PASSWORD" ]; then
       echo >&2 'error: Couchbase not initialized because CLUSTER_INIT_USER or CLUSTER_INIT_PASSWORD was not set'
       echo >&2 '       Did you forget to add -e CLUSTER_INIT_USER=... -e CLUSTER_INIT_PASSWORD=... ?'
       exit 1
fi

if [ -z "$COUCHBASE_PORT_8091_TCP" ]; then

    if [ -z "$CLUSTER_RAM_SIZE" ]; then
        CLUSTER_RAM_SIZE=1024
    fi

    echo 'initializing cluster...'
    wait_for_start /opt/couchbase/bin/couchbase-cli cluster-init -c 127.0.0.1:8091 --cluster-init-username="$CLUSTER_INIT_USER" --cluster-init-password="$CLUSTER_INIT_PASSWORD" --cluster-init-ramsize="$CLUSTER_RAM_SIZE" -u "$CLUSTER_INIT_USER" -p "$CLUSTER_INIT_PASSWORD"

    if [ -n "$SAMPLE_BUCKETS" ]; then
    curl http://"$CLUSTER_INIT_USER":"$CLUSTER_INIT_PASSWORD"@127.0.0.1:8091/sampleBuckets/install --data "[$SAMPLE_BUCKETS]"
    fi
else
    ip=`hostname --ip-address`
    wait_for_start /opt/couchbase/bin/couchbase-cli server-add -c $COUCHBASE_PORT_8091_TCP_ADDR:$COUCHBASE_PORT_8091_TCP_PORT --user="$CLUSTER_INIT_USER" --password="$CLUSTER_INIT_PASSWORD" --server-add=$ip:8091
fi

trap "/etc/init.d/couchbase-server stop" exit INT TERM

pid_file=/opt/couchbase/var/lib/couchbase/couchbase-server.pid
# can't use 'wait $(<"$pid_file")' as process not child of shell
while [ -e /proc/$(<"$pid_file") ]; do sleep 1; done

Thanks & Regards
Camillelola

Hi Camillelola,
Would you be able to share the Dockerfile for the couchbase server and couchbase-data and the command that you ran to run the containsers?
I will try from my side and see if I can replicate it.
Thanks,
-Jae