Skip to content

Instantly share code, notes, and snippets.

@rajagp
Last active October 25, 2022 09:47
Show Gist options
  • Select an option

  • Save rajagp/8d05314d85fcbf169ee39a671077a566 to your computer and use it in GitHub Desktop.

Select an option

Save rajagp/8d05314d85fcbf169ee39a671077a566 to your computer and use it in GitHub Desktop.
Steps to create a custom Couchbase Server Docker Image for development
  • 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
   docker logs -f cb-server
@paschalis-mpeis
Copy link
Copy Markdown

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

@kirangandhi
Copy link
Copy Markdown

All,
Anybody tried upgrade procedure without loosing existing data? I tried upgrade by removing old image and putting new image where data is stored in separate partition and it is visible to container but data is not recognized by new image.

@habil
Copy link
Copy Markdown

habil commented Aug 5, 2020

If you get "permission denied" error while running, check the .sh file write permissions. By the way, thank you!

@DanielSchlette
Copy link
Copy Markdown

DanielSchlette commented May 17, 2021

Hello,
thanks for the clear write up. As @habil pointed out, for the permission add

RUN chmod +x configure-server.sh

to the dockerfile. Also (in my case) use fg instead of fg 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment