1

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
3

You should consider preserving the entire /opt/couchbase/var directory in a volume, rather than just the /opt/couchbase/var/lib/couchbase/data subdirectory.

The reason is that there is "cluster state" stored in /opt/couchbase/var. If that's lost, it will think it's a brand new cluster on a new container instance.

I wrote up a blog post which walks through a complete example of spinning up couchbase server under docker. The Dockerfile and all scripts used are on github.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.