Over a million developers have joined DZone.

Couchbase Cluster Using Docker Compose

DZone's Guide to

Couchbase Cluster Using Docker Compose

How to easily set up a 3-node Couchbase cluster using Docker Compose that will let you scale Couchbase with solid performance.

· Database Zone ·
Free Resource

Slow SQL Server? These SentryOne resources share tips and tricks for not only troubleshooting SQL Server performance issues, but also preventing them before they hit your production environment.

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:

  image: couchbase/server
    - ~/couchbase/node1:/opt/couchbase/var
  image: couchbase/server
    - ~/couchbase/node2:/opt/couchbase/var
  image: couchbase/server
    - ~/couchbase/node3:/opt/couchbase/var
    - 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>8091-8093/tcp, 11207/tcp, 11211/tcp,>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,>11210/tcp,   
                                                                                                                               11211/tcp, 18091/tcp, 18092/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
  2. Access Couchbase Admin Console at http://<DOCKER_MACHINE_IP:8091. This is in our case. It will show the output as: Docker Couchbase Cluster Setup

    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
    Use this IP address to change the Hostname field:Docker Couchbase Cluster Node 1
  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 Per Node RAM Quota
  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

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
  2. Find IP address of one of the remaining nodes:
    docker inspect --format '{{ .NetworkSettings.IPAddress }}' couchbasecluster_couchbase1_1
  3. Click on “Add Server”, specify the IP address: Docker Couchbase Cluster Add Server Node1
    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

Click on “Rebalance” and this will automatically rebalance the cluster:

Docker Couchbase Cluster Rebalanced

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

Database monitoring tools letting you down? See how SentryOne empowers Enterprises to go faster.

couchbase ,docker

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}