Developer Open source

How to deploy CouchDB as a cluster with Docker

IT man working on laptop computer
Image: DragonImages/Adobe Stock

Recently, I confirmed you ways to deploy CouchDB as a standalone NoSQL database server, which might serve you properly in small cases. This time round, I would like to present you a neat trick for deploying CouchDB as a cluster utilizing Docker. Although this technique may not be superb for manufacturing utilization, it’s a good way for builders to find a way to work with CouchDB in a check atmosphere.

Without additional ado, let’s get to the deployment.

SEE: Hiring package: Back-end Developer (TechRepublic Premium)

What you’ll want

To make this work, you’ll want a server with an OS that helps Docker. I’ll exhibit with Ubuntu Server 22.04, however you should utilize whichever platform you’re snug with.

How to set up Docker

On the off-chance you don’t have already got Docker put in, right here’s the way you do it.

First, add the official Docker GPG key with the command:

curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Next, add the required repository:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $(lsb_release -cs) steady" | sudo tee /and many others/apt/sources.checklist.d/docker.checklist > /dev/null

Install the required dependencies with:

sudo apt-get set up apt-transport-https ca-certificates curl gnupg lsb-release -y

Finally, we will set up the most recent model of the Docker engine:

sudo apt-get replace

sudo apt-get set up docker-ce docker-ce-cli -y

Add your person to the docker group with the command:

sudo usermod -aG docker $USER

Make the system conscious of the change with:

newgrp docker

How to deploy the CouchDB containers

We’re going to deploy three CouchDB containers, every utilizing a distinctive exterior port. The first will use port 5984 and is deployed with:

docker run -itd -p 5984:5984 -p 5986:5986 --name=couchdb0 -e NODENAME='' --mount 'supply=volume-0,goal=/decide/couchdb/information' couchdb:2.3.0

The second container is deployed (utilizing port 15984) with:

docker run -itd -p 15984:5984 -p 15986:5986 --name=couchdb1 -e  NODENAME='' --mount 'supply=volume-1,goal=/decide/couchdb/information' couchdb:2.3.0

The last container is deployed *utilizing port 25984) with:

docker run -itd -p 25984:5984 -p 25986:5986 --name=couchdb2 -e NODENAME='' --mount 'supply=volume-2,goal=/decide/couchdb/information' couchdb:2.3.0

If you challenge the command docker ps -a | grep couchdb it is best to see all three cases up and operating.

How to create the administrator person

We now want to create an administrator on every container. In every occasion, substitute PASSWORD with a sturdy password (be certain that it’s the identical for every). The instructions for this shall be:

curl -X PUT http://localhost:5984/_node/ -d '"PASSWORD"
curl -X PUT http://localhost:15984/_node/ -d '"PASSWORD"
curl -X PUT http://localhost:25984/_node/ -d '"PASSWORD"''

Outstanding. Let’s proceed.

How to create a Docker community

At the second, the CouchDB nodes don’t have any consciousness of each other. To repair that we want to create a new Docker community. Do this with:

docker community create -d bridge --subnet isolated_nw

With our community created, we now have to join our containers to it, which is completed utilizing the next instructions:

docker community join --alias isolated_nw couchdb0
docker community join --alias isolated_nw couchdb1
docker community join --alias isolated_nw couchdb2


How to log into the admin console

Open a internet browser and level it to http://server:5984, the place SERVER is the IP deal with of the server internet hosting Docker. Log in with the username admin and the password you added for the admin person earlier.

Once you’ve logged in, click on the wrench icon within the left navigation after which click on Configure a Cluster (Figure A).

Figure A

The CouchDB Setup window.

In the ensuing window (Figure B), you’ll want to fill within the admin credentials after which add a node to the cluster.

Figure B

The CouchDB cluster configuration window.

To add the primary node to the cluster, you’ll sort as the Remote Host and depart the port at 5984. Once you’ve performed that, click on Add Node. Do the identical factor for the second node utilizing as the Remote Host.

After including each nodes, click on Configure Cluster and you need to be rewarded with a web page informing you the cluster has been configured (Figure C).

Figure C

The cluster is up and operating.

Congratulations, you’ve simply deployed your first CouchDB cluster, with the assistance of Docker.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the most recent tech recommendation for enterprise execs from Jack Wallen.


Leave a Reply

Your email address will not be published.Required fields are marked *