Follow the steps below if you are interested in creating your own custom configurable Couchbase docker image. You will start off with the official Couchbase Enterprise docker image that is available on Docker Hub and use the Couchbase CLI and REST interface to create a custom configurable image.
This approach inspired by the tutorial. We essentially built a custom docker image from the base Coucbase server image that is configured for our development needs!
- Create a new file named
DockerFile
and open it using an editor of your choice - Now add the following lines to the
DockerFile
.
FROM couchbase
COPY configure-server.sh /opt/couchbase
CMD ["/opt/couchbase/configure-server.sh"]
- Create a new file named
configure-server.sh
an open it using an editor of your choice - Now add the following lines to the
configure-server.sh
. We are using the CLI and REST commands to configure the cluster, the Administrator user, the bucket and the RBAC user. You can update this script according to your configuration needs.
set -m
/entrypoint.sh couchbase-server &
sleep 15
# Setup initial cluster/ Initialize Node
couchbase-cli cluster-init -c 127.0.0.1 --cluster-name $CLUSTER_NAME --cluster-username $COUCHBASE_ADMINISTRATOR_USERNAME \
--cluster-password $COUCHBASE_ADMINISTRATOR_PASSWORD --services data,index,query,fts --cluster-ramsize 256 --cluster-index-ramsize 256 \
--cluster-fts-ramsize 256 --index-storage-setting default \
# Setup Administrator username and password
curl -v http://127.0.0.1:8091/settings/web -d port=8091 -d username=$COUCHBASE_ADMINISTRATOR_USERNAME -d password=$COUCHBASE_ADMINISTRATOR_PASSWORD
sleep 15
# Setup Bucket
couchbase-cli bucket-create -c 127.0.0.1:8091 --username $COUCHBASE_ADMINISTRATOR_USERNAME \
--password $COUCHBASE_ADMINISTRATOR_PASSWORD --bucket $COUCHBASE_BUCKET --bucket-type couchbase \
--bucket-ramsize 256
sleep 15
# Setup RBAC user using CLI
couchbase-cli user-manage -c 127.0.0.1:8091 --username $COUCHBASE_ADMINISTRATOR_USERNAME --password $COUCHBASE_ADMINISTRATOR_PASSWORD \
--set --rbac-username $COUCHBASE_RBAC_USERNAME --rbac-password $COUCHBASE_RBAC_PASSWORD --rbac-name $COUCHBASE_RBAC_NAME \
--roles bucket_full_access[*],bucket_admin[*] --auth-domain local
fg 1
- Build the custom Docker Image using the
DockerFile
. The name of the image iscouchbase-dev
docker build -t couchbase-dev .
- Once you have succesfully built the custom image, you can run it by providing the appropriate configuration options. Note that we have provided appropriate values for the parameters defined in the
configure-server.sh
file.
$ docker run -d --name cb-server -p 8091-8094:8091-8094 -p 11210:11210 -e COUCHBASE_ADMINISTRATOR_USERNAME=Administrator -e COUCHBASE_ADMINISTRATOR_PASSWORD=password -e COUCHBASE_BUCKET=demobucket -e COUCHBASE_RBAC_USERNAME=admin -e COUCHBASE_RBAC_PASSWORD=password -e COUCHBASE_RBAC_NAME="admin" -e CLUSTER_NAME=demo-cluster couchbase-dev
- You can view the logs at any time by running the following command
docker logs -f cb-server
You can get a latest docker image of Couchbase Server generated from the above script
docker pull priyacouch/couchbase-dev
Hello,
thanks for the clear write up. As @habil pointed out, for the permission add
to the dockerfile. Also (in my case) use fg instead of fg 1