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.
Join the DZone community and get the full member experience.
Join For FreeCouchbase 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.
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.
- Create three directories
~couchbase/node1
,~couchbase/node2
,~couchbase/node3
– one for each node. - Start three Couchbase nodes as using the
docker-compose.yml
shown earlier:241> docker-compose up -d
2Pulling couchbase1 (couchbase/server:latest)...
3latest: Pulling from couchbase/server
470618b6e8070: Pull complete
505820377a11a: Pull complete
68de88a91bde5: Pull complete
761994089e28e: Pull complete
8bc191c81777b: Pull complete
9939d0c2514c9: Pull complete
10fa75256f7885: Pull complete
117bc9fb79dd30: Pull complete
12e4c99c5f6106: Pull complete
13307ac999aa30: Pull complete
1424eeb78ce9ab: Pull complete
15c4180973b487: Pull complete
166e0c54ca80e7: Pull complete
17c6d69cc874d9: Pull complete
1831485a5bae7a: Pull complete
1931c8df734d6b: Pull complete
20Digest: sha256:0e983929897ae9bd396533ff7875f30027290c6acf164a66c967ca8884507381
21Status: Downloaded newer image for couchbase/server:latest
22Creating couchbasecluster_couchbase1_1
23Creating couchbasecluster_couchbase3_1
24Creating couchbasecluster_couchbase2_1
This command is given on a Docker Machine. - Check status of the nodes:51
> docker ps
2CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
307ff4f1823a4 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
418f7bf07134a 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
54db3e1280776 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:141> docker-compose ps
2Name Command State Ports
3-----------------------------------------------------------------------------------------------------------------------------------------------------------------
4couchbasecluster_couchbase1_1 /entrypoint.sh couchbase-s ... Up 11207/tcp, 11210/tcp, 11211/tcp,
518091/tcp, 18092/tcp, 8091/tcp,
68092/tcp, 8093/tcp
7couchbasecluster_couchbase2_1 /entrypoint.sh couchbase-s ... Up 11207/tcp, 11210/tcp, 11211/tcp,
818091/tcp, 18092/tcp, 8091/tcp,
98092/tcp, 8093/tcp
10couchbasecluster_couchbase3_1 /entrypoint.sh couchbase-s ... Up 11207/tcp, 0.0.0.0:11210->11210/tcp,
1111211/tcp, 18091/tcp, 18092/tcp,
120.0.0.0:8091->8091/tcp,
130.0.0.0:8092->8092/tcp,
140.0.0.0:8093->8093/tcp
- Check logs of the nodes:51
> docker-compose logs
2Attaching to couchbasecluster_couchbase2_1, couchbasecluster_couchbase3_1, couchbasecluster_couchbase1_1
3couchbase2_1 | Starting Couchbase Server -- Web UI available at http://<ip>:8091
4couchbase3_1 | Starting Couchbase Server -- Web UI available at http://<ip>:8091
5couchbase1_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.
- Find IP address of the Docker Machine:21
> docker-machine ip default
2192.168.99.104
- 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:
Click on “Setup”. - 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: Use this IP address to change the Hostname field:1
> docker inspect --format '{{ .NetworkSettings.IPAddress }}' couchbasecluster_couchbase3_1
2172.17.0.2
- Click on “Next”. Adjust the RAM if necessary. Read more about Couchbase Cluster Settings.
- Pick a sample bucket that you’d like to get installed, and click on Next.
- Change Per Node RAM Quota from 400 to 100. This is required as we’ll add other nodes later.
- Click on Next, accept T&C, and click on Next.
- 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:
Add More Couchbase Nodes
Now, lets add the other two nodes that were created earlier by Docker Compose.
- Click on “Server Nodes” to see the default view as:
- Find IP address of one of the remaining nodes: 21
docker inspect --format '{{ .NetworkSettings.IPAddress }}' couchbasecluster_couchbase1_1
2172.17.0.1
- Click on “Add Server”, specify the IP address:
and click on “Add Server”. - 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:
Click on “Rebalance” and this will automatically rebalance the cluster:
You just deployed a Couchbase cluster using Docker Compose, enjoy!
Published at DZone with permission of Arun Gupta, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments