Run couchbase

docker run -d --name couchbase \
    -p 8091-8094:8091-8094 \
    -p 11210:11210 \
    -v $(pwd)/data:/opt/couchbase/var:rw \
    couchbase:community-5.1.1

Backup couchbase

BACKUP_TYPE=full
DEST=$(pwd)/backup
USER=Administrator
PASS=couchbase
mkdir -p $DEST

# You can only use Docker for Mac in order to use `host.docker.internal`
docker run -v $DEST:/backup --rm couchbase:community-5.1.1 /opt/couchbase/bin/cbbackup -m ${BACKUP_TYPE} \
    http://host.docker.internal:8091 /backup \
    -u ${USER} -p ${PASS} 2>&1

Restore couchbase

# Need to create the destination bucket before restoring the data
SOURCE=$(pwd)/backup/
USER=Administrator
PASS=couchbase
BUCKET=default

buckets=("sample1" "sample2" "sample3")
for i in "${buckets[@]}"
do
    BUCKET="$i"
    echo $BUCKET
    docker run -v $SOURCE:/backup --rm couchbase:community-5.1.1 /opt/couchbase/bin/cbrestore /backup \
        http://host.docker.internal:8091 \
        -b ${BUCKET} \
        -u ${USER} -p ${PASS} 2>&1
done

Export couchbase data

docker run \
    -v /opt/couchbase-data/:/opt/couchbase-data/ \
    --network network \
    --rm \
    couchbase:community-5.1.1 \
    /opt/couchbase/bin/cbtransfer http://couchbase:8091 csv:/opt/couchbase-data/data.csv \
    -b bucket -u Administrator -p password

Reference