- 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
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_admin[*] --auth-domain local
fg 1
- Build the custom Docker Image using the
DockerFile. The name of the image is couchbase-dev
docker build -t couchbase-dev .
- Once you have succesfully built the custom image, you can launch it. Open a terminal window and type the following command. Note that we have provided appropriate values for the parameters defined in the
configure-server.sh file.
$ docker run -d --name cb-server --network cbnetwork -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-user" -e CLUSTER_NAME=demo-cluster couchbase-dev
- You can view the logs at any time by running the following command
Hello there.
I have been trying to automatically setup a cluster with docker.
I have found quite a few scripts similar with yours, however how can server-configure.sh ever return and terminate,
if the couchbase server starts and is put to the background (with &), and then brough to the foreground (fg 1).
Regards,
Paschalis