VOOZH about

URL: https://www.javacodegeeks.com/2015/10/couchbase-cluster-using-docker-compose.html

โ‡ฑ Couchbase Cluster using Docker Compose - Java Code Geeks


Couchbase 4.0 provides lots of features that allows you to develop with agility and operate at any scale. Some of the features that allow you to operate at any scale are:

  • Elastic Scalability
  • Consistent High Performance
  • Always-On Availability
  • Multi-Data Center Deployment
  • Simple and Powerful Administration
  • Enterprise-grade Security

Learn more about these enterprise features at couchbase.com/operate-at-any-scale.

A complete overview is available in Couchbase Server 4.0 datasheet.

This blog will explain how you can easily setup a 3-node Couchbase Cluster using Docker Compose.

๐Ÿ‘ docker-couchbase-cluster

The source code and latest instructions are available at github.com/arun-gupta/docker-images/tree/master/couchbase-cluster.

Create Couchbase Nodes

Couchbase cluster can be easily created using the following Docker Compose file:

couchbase1:
 image: couchbase/server
 volumes:
 - ~/couchbase/node1:/opt/couchbase/var
couchbase2:
 image: couchbase/server
 volumes:
 - ~/couchbase/node2:/opt/couchbase/var
couchbase3:
 image: couchbase/server
 volumes:
 - ~/couchbase/node3:/opt/couchbase/var
 ports:
 - 8091:8091
 - 8092:8092 
 - 8093:8093 
 - 11210:11210

This file has service definition for three Couchbase nodes. Admin ports are exposed for only one node as other nodes will talk to each other use Docker-internally assigned IP addresses.

  1. Create three directories ~couchbase/node1, ~couchbase/node2, ~couchbase/node3 โ€“ one for each node.
  2. Start three Couchbase nodes as using the docker-compose.yml shown earlier:
    > docker-compose up -d
    Pulling couchbase1 (couchbase/server:latest)...
    latest: Pulling from couchbase/server
    70618b6e8070: Pull complete
    05820377a11a: Pull complete
    8de88a91bde5: Pull complete
    61994089e28e: Pull complete
    bc191c81777b: Pull complete
    939d0c2514c9: Pull complete
    fa75256f7885: Pull complete
    7bc9fb79dd30: Pull complete
    e4c99c5f6106: Pull complete
    307ac999aa30: Pull complete
    24eeb78ce9ab: Pull complete
    c4180973b487: Pull complete
    6e0c54ca80e7: Pull complete
    c6d69cc874d9: Pull complete
    31485a5bae7a: Pull complete
    31c8df734d6b: Pull complete
    Digest: sha256:0e983929897ae9bd396533ff7875f30027290c6acf164a66c967ca8884507381
    Status: Downloaded newer image for couchbase/server:latest
    Creating couchbasecluster_couchbase1_1
    Creating couchbasecluster_couchbase3_1
    Creating couchbasecluster_couchbase2_1

    This command is given on a Docker Machine.

  3. Check status of the nodes:
    > docker ps
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    07ff4f1823a4 couchbase/server "/entrypoint.sh couch" 5 minutes ago Up 5 minutes 8091-8093/tcp, 11207/tcp, 11210-11211/tcp, 18091-18092/tcp couchbasecluster_couchbase2_1
    18f7bf07134a couchbase/server "/entrypoint.sh couch" 5 minutes ago Up 5 minutes 0.0.0.0:8091-8093->8091-8093/tcp, 11207/tcp, 11211/tcp, 0.0.0.0:11210->11210/tcp, 18091-18092/tcp couchbasecluster_couchbase3_1
    4db3e1280776 couchbase/server "/entrypoint.sh couch" 5 minutes ago Up 5 minutes 8091-8093/tcp, 11207/tcp, 11210-11211/tcp, 18091-18092/tcp couchbasecluster_couchbase1_1
    

    Docker Compose can also show the status:

    > docker-compose ps
     Name Command State Ports 
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------
    couchbasecluster_couchbase1_1 /entrypoint.sh couchbase-s ... Up 11207/tcp, 11210/tcp, 11211/tcp, 
     18091/tcp, 18092/tcp, 8091/tcp, 
     8092/tcp, 8093/tcp 
    couchbasecluster_couchbase2_1 /entrypoint.sh couchbase-s ... Up 11207/tcp, 11210/tcp, 11211/tcp, 
     18091/tcp, 18092/tcp, 8091/tcp, 
     8092/tcp, 8093/tcp 
    couchbasecluster_couchbase3_1 /entrypoint.sh couchbase-s ... Up 11207/tcp, 0.0.0.0:11210->11210/tcp, 
     11211/tcp, 18091/tcp, 18092/tcp, 
     0.0.0.0:8091->8091/tcp, 
     0.0.0.0:8092->8092/tcp, 
     0.0.0.0:8093->8093/tcp
    
  4. Check logs of the nodes:
    > docker-compose logs
    Attaching to couchbasecluster_couchbase2_1, couchbasecluster_couchbase3_1, couchbasecluster_couchbase1_1
    couchbase2_1 | Starting Couchbase Server -- Web UI available at http://<ip>:8091
    couchbase3_1 | Starting Couchbase Server -- Web UI available at http://<ip>:8091
    couchbase1_1 | Starting Couchbase Server -- Web UI available at http://<ip>:8091
    

Configure Couchbase Cluster

Lets configure these nodes to be part of a cluster now.

  1. Find IP address of the Docker Machine:
    >> docker-machine ip default
    192.168.99.104
  2. Access Couchbase Admin Console at http://<DOCKER_MACHINE_IP:8091. This is http://192.168.99.104:8091 in our case. It will show the output as:
     
    ๐Ÿ‘ docker-couchbase-cluster-setup-1024x717

    Click on โ€œSetupโ€.
  3. Each container is given an internal IP address by Docker, and each of these IPs is visible to all other containers running on the same host. We need to use these internal IP address when adding a new node to the cluster.Find IP address of the first container:
    > docker inspect --format '{{ .NetworkSettings.IPAddress }}' couchbasecluster_couchbase3_1
    172.17.0.2

    Use this IP address to change the Hostname field:

    ๐Ÿ‘ docker-couchbase-cluster-node1-e1445384614211-1024x952

  4. Click on โ€œNextโ€. Adjust the RAM if necessary. Read more about Couchbase Cluster Settings.
  5. Pick a sample bucket that youโ€™d like to get installed, and click on Next.
  6. Change Per Node RAM Quota from 400 to 100. This is required as weโ€™ll add other nodes later.
     
    ๐Ÿ‘ docker-couchbase-cluster-node-ram-quota-1024x594
  7. Click on Next, accept T&C, and click on Next.
  8. Enter a password that you can remember as weโ€™ll need this later to add more nodes.

Default view of the cluster looks like as shown:

๐Ÿ‘ docker-couchbase-cluster-default-view-1024x409

Add More Couchbase Nodes

Now, lets add the other two nodes that were created earlier by Docker Compose.

  1. Click on โ€œServer Nodesโ€ to see the default view as:
     
    ๐Ÿ‘ docker-couchbase-cluster-server-nodes-default-view-1024x316
  2. Find IP address of one of the remaining nodes:
    docker inspect --format '{{ .NetworkSettings.IPAddress }}' couchbasecluster_couchbase1_1
    172.17.0.1
  3. Click on โ€œAdd Serverโ€, specify the IP address:
     
    ๐Ÿ‘ docker-couchbase-cluster-add-server-node1-1024x910

    and click on โ€œAdd Serverโ€.
  4. Repeat the previous two steps with the server name couchbasecluster_couchbase2_1.

Couchbase Cluster Rebalance

A cluster needs to be rebalanced to ensured that the data is well distributed amongst the newly added or removed nodes. Read more about Couchbase Cluster Rebalance.

Clicking on โ€œPending Rebalanceโ€ tab shows the nodes that have been added to the cluster but are not rebalanced yet:

๐Ÿ‘ docker-couchbase-cluster-pending-rebalance-1024x367

Click on โ€œRebalanceโ€ and this will automatically rebalance the cluster:

๐Ÿ‘ docker-couchbase-cluster-rebalanced-1024x409

You just deployed a Couchbase cluster using Docker Compose, enjoy!

Some more references:

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

๐Ÿ‘ Photo of Arun Gupta
Arun Gupta
October 26th, 2015Last Updated: October 26th, 2015
0 95 3 minutes read

Arun Gupta

Arun is a technology enthusiast, avid runner, author of a best-selling book, globe trotter, a community guy, Java Champion, JavaOne Rockstar, JUG Leader, Minecraft Modder, Devoxx4Kids-er, and a Red Hatter.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz